Getting started with systemd contains examples of enabling, starting, and stopping containers. Docker container as a Linux system service uses docker start -a
/docker stop
to start/stop containers.
[Unit]
Description=MySQL
After=docker.service
Wants=network-online.target docker.socket
Requires=docker.socket
[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/docker start -a mysql
ExecStop=/usr/bin/docker stop mysql
[Install]
WantedBy=multi-user.target
systemctl enable mysql
systemctl start mysql
systemctl stop mysql
If the mysql.service file is changed, use systemctl daemon-reload
to reflect the changes.