Skip to content

Instantly share code, notes, and snippets.

@nothub
Created January 30, 2021 01:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nothub/294a2ae9d78f210b1d8842293c0d9af3 to your computer and use it in GitHub Desktop.
Save nothub/294a2ae9d78f210b1d8842293c0d9af3 to your computer and use it in GitHub Desktop.
docker-compose systemd unit template
[Unit]
Description=%i (docker-compose)
Requires=docker.service
After=docker.service
[Service]
Restart=always
TimeoutStartSec=300
# restart twice a day to pull image updates
RuntimeMaxSec=43200
# services reside in /opt/docker/<SERVICENAME>
# example: /opt/docker/service-a/docker-compose.yml
WorkingDirectory=/opt/docker/%i
# remove old containers and update image
ExecStartPre=/usr/local/bin/docker-compose rm --force --stop
ExecStartPre=/usr/local/bin/docker-compose pull
# compose up (compatibility for pre docker machine stuff)
ExecStart=/usr/local/bin/docker-compose --compatibility up
# compose down, remove containers
ExecStop=/usr/local/bin/docker-compose down --timeout 60
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment