Created
July 10, 2023 20:40
-
-
Save tyzbit/d464d9719c521c6b99054417ffaca90f to your computer and use it in GitHub Desktop.
Docker-Compose Systemd script
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
[Unit] | |
Description=%i service | |
Requires=docker.service | |
After=docker.service | |
[Service] | |
Restart=always | |
User=root | |
Group=docker | |
WorkingDirectory=/services/%i | |
# Shutdown container (if running) when unit is started | |
ExecStartPre=/usr/bin/docker-compose -f docker-compose.yml down | |
# Start container when unit is started | |
ExecStart=/usr/bin/docker-compose -f docker-compose.yml up | |
# Stop container when unit is stopped | |
ExecStop=/usr/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
Prerequisites
docker
anddocker-compose
must be installed.How to use
In these commands, replace
appname
with whatever you want to call your app/service combo./etc/systemd/system/
mkdir -p /services/appname
docker-compose.yml
in/services/appname
sudo systemctl daemon-reload
sudo systemctl enable app@appname
sudo systemctl start app@appname
To read logs
journalctl -u app@appname -f