Skip to content

Instantly share code, notes, and snippets.

@sarim
Created December 30, 2022 22:31
Show Gist options
  • Save sarim/90fc727afdb035ece668c1e263e04fa6 to your computer and use it in GitHub Desktop.
Save sarim/90fc727afdb035ece668c1e263e04fa6 to your computer and use it in GitHub Desktop.
mysql podman container as systemd service

mysql podman container as systemd service

compose file initially run by podman-compose to create first container. Might need to run with --initialize first time to init the datadir directory structure. systemd unit file generated by podman generate systemd mysql5 --new. Then edited ExecStartPre.

setting socket path in /etc/mysql/conf.d/mysql.cnf needed for default mysql client command. Custom mysql setting like tuning cache size etc.. can be put into customconf dir.

version: '3'
services:
mysql5:
image: docker.io/mysql:5-oracle
container_name: mysql5
# NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
# (this is just an example, not intended to be a production configuration)
# command: --default-authentication-plugin=mysql_native_password
# not relevant as we're using mysql v5
restart: always
# command: --initialize
environment:
MYSQL_ROOT_PASSWORD: EDIT_MYSQL_ROOT_PASSWORD
volumes:
- /opt/mysql-container/datadir:/var/lib/mysql
- /opt/mysql-container/sockdir:/var/run/mysqld
- /opt/mysql-container/logdir:/var/log
- /opt/mysql-container/customconf:/etc/mysql/conf.d
ports:
- 3306:3306
[mysql]
socket=/opt/mysql-container/sockdir/mysqld.sock
# container-mysql5.service
# autogenerated by Podman 3.4.4
# Wed Oct 12 02:18:25 UTC 2022
[Unit]
Description=Podman container-mysql5.service
Documentation=man:podman-generate-systemd(1)
Wants=network-online.target
After=network-online.target
RequiresMountsFor=%t/containers
[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=always
TimeoutStopSec=70
ExecStartPre=/bin/rm -f %t/%n.ctr-id
ExecStart=/usr/bin/podman run --cidfile=%t/%n.ctr-id --cgroups=no-conmon --rm --sdnotify=conmon --replace --name=mysql5 -d --label io.podman.compose.config-hash=60e52d5e30ce4d2c9b3a904a534e7e62600c0ba8148fcc04b5c30088401e04c4 --label io.podman.compose.project=mysql-container --label io.podman.compose.version=1.0.4 --label [email protected] --label com.docker.compose.project=mysql-container --label com.docker.compose.project.working_dir=/opt/mysql-container --label com.docker.compose.project.config_files=docker-compose.yml --label com.docker.compose.container-number=1 --label com.docker.compose.service=mysql5 -e MYSQL_ROOT_PASSWORD=EDIT_MYSQL_ROOT_PASSWORD -v /opt/mysql-container/datadir:/var/lib/mysql -v /opt/mysql-container/sockdir:/var/run/mysqld -v /opt/mysql-container/logdir:/var/log -v /opt/mysql-container/customconf:/etc/mysql/conf.d --net mysql-container_default --network-alias mysql5 -p 3306:3306 docker.io/mysql:5-oracle
ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id
Type=notify
NotifyAccess=all
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment