Skip to content

Instantly share code, notes, and snippets.

@jpcaparas
Last active July 14, 2019 09:15
Show Gist options
  • Save jpcaparas/30e733251f95412fa4782c9b9fba9ecd to your computer and use it in GitHub Desktop.
Save jpcaparas/30e733251f95412fa4782c9b9fba9ecd to your computer and use it in GitHub Desktop.
docker-compose systemd template
# Start the service
sudo systemctl start docker-compose@myservice
# Enable the service at runtime
sudo systemctl enable docker-compose@myservice
# Disable the service at runtime
sudo systemctl enable docker-compose@myservice
# Stop the service
sudo systemctl stop docker-compose@myservice
# View the logs
sudo journalctl -f -b -u docker-compose@myservice
[Unit]
# Bare minimum config to get docker-compose as a systemd service running
# Reference: https://gist.github.com/mosquito/b23e1c1e5723a7fd9e6568e5cf91180f
Description=%i service with docker-compose
Requires=docker.service
After=docker.service
[Service]
WorkingDirectory=/opt/docker-repos/%i
TimeoutStartSec=20s
RestartSec=5s
Restart=always
ExecStart=/usr/bin/docker-compose -f docker-compose.yml up
ExecStop=/usr/bin/docker-compose -f docker-compose.yml down -v
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment