Last active
March 22, 2018 21:08
-
-
Save cristiroma/d5df0c877f87d56632d9 to your computer and use it in GitHub Desktop.
CentOS 7 systemd script to start/stop docker containers at boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://goldmann.pl/blog/2014/07/30/running-docker-containers-as-systemd-services/ | |
[Unit] | |
Description=MariaDB container | |
Requires=docker.service | |
After=docker.service | |
[Service] | |
User=php | |
Restart=always | |
RestartSec=10 | |
# ExecStartPre=-/usr/bin/docker kill database | |
# ExecStartPre=-/usr/bin/docker rm database | |
ExecStart=/usr/bin/docker start -a database | |
ExecStop=/usr/bin/docker stop -t 2 database | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To enable the service, you need to:
/etc/systemd/system/docker.database.service
systemctl enable docker.database.service
Notes:
systemctl start docker.database.service
systemctl daemon-reload
Don't forget to reboot the machine to test the script!