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 hidden or 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
dockeranddocker-composemust be installed.How to use
In these commands, replace
appnamewith whatever you want to call your app/service combo./etc/systemd/system/mkdir -p /services/appnamedocker-compose.ymlin/services/appnamesudo systemctl daemon-reloadsudo systemctl enable app@appnamesudo systemctl start app@appnameTo read logs
journalctl -u app@appname -f