Skip to content

Instantly share code, notes, and snippets.

@avin
Created June 28, 2022 19:00
Show Gist options
  • Save avin/b3832ad22a44d7b201b91eac9f92646b to your computer and use it in GitHub Desktop.
Save avin/b3832ad22a44d7b201b91eac9f92646b to your computer and use it in GitHub Desktop.
Systemd (systemctl) docker-compse based service
# File location: /etc/systemd/system
# Enable service to autostart: systemctl enable foo.service
[Unit]
Description=foo
Requires=docker.service
After=docker.service
[Service]
Restart=always
WorkingDirectory=/opt/foo/
ExecStartPre=/usr/local/bin/docker-compose -f docker-compose.yml down -v
ExecStart=/usr/local/bin/docker-compose -f docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f docker-compose.yml down
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment