-
-
Save eltechno/6ba65fd3e2cec249090bb000d25a5634 to your computer and use it in GitHub Desktop.
Running docker-compose as a systemd service
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
# Running docker-compose as a systemd service | |
## Files | |
| File | Purpose | | |
| ---- | ---- | | |
| `/etc/compose/docker-compose.yml` | Compose file describing what to deploy | | |
| `/etc/systemd/system/docker-compose.service` | Service unit to start and manage docker compose | | |
| `/etc/systemd/system/docker-compose-reload.service` | Executing unit to trigger reload on `docker-compose.service` | | |
| `/etc/systemd/system/docker-compose-reload.timer` | Timer unit to plan the reloads | | |
## Installation | |
Put the above mentioned files in the corresponding places and let systemd load them: | |
```bash | |
# systemctl daemon-reload | |
# systemctl enable docker-compose docker-compose-reload | |
# systemctl start docker-compose docker-compose-reload | |
``` |
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=Refresh images and update containers | |
[Service] | |
Type=oneshot | |
ExecStart=/bin/systemctl reload docker-compose.service |
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=Refresh images and update containers | |
Requires=docker-compose.service | |
After=docker-compose.service | |
[Timer] | |
OnCalendar=*:0/15 | |
[Install] | |
WantedBy=timers.target |
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=Docker Compose container starter | |
After=docker.service network-online.target | |
Requires=docker.service network-online.target | |
[Service] | |
WorkingDirectory=/etc/compose | |
Type=oneshot | |
RemainAfterExit=yes | |
ExecStartPre=/usr/local/bin/docker-compose pull --quiet --parallel | |
ExecStart=/usr/local/bin/docker-compose up -d | |
ExecStop=/usr/local/bin/docker-compose down | |
ExecReload=/usr/local/bin/docker-compose pull --quiet --parallel | |
ExecReload=/usr/local/bin/docker-compose up -d | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment