Created
May 8, 2021 20:16
-
-
Save twogood/3ed99fe27e70f3bad3e465deac614931 to your computer and use it in GitHub Desktop.
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 with docker compose | |
Requires=docker.service | |
After=docker.service | |
[Service] | |
SyslogIdentifier=%i | |
Restart=always | |
WorkingDirectory=/etc/docker/compose/%i | |
# Remove old containers, images and volumes | |
ExecStartPre=/opt/bin/docker-compose down -v | |
ExecStartPre=/opt/bin/docker-compose rm -fv | |
ExecStartPre=-/bin/bash -c 'docker volume ls -qf "name=%i_" | xargs docker volume rm' | |
ExecStartPre=-/bin/bash -c 'docker network ls -qf "name=%i_" | xargs docker network rm' | |
ExecStartPre=-/bin/bash -c 'docker ps -aqf "name=%i_*" | xargs docker rm' | |
# Compose up | |
ExecStart=/opt/bin/docker-compose up | |
# Compose down, remove containers and volumes | |
ExecStop=/opt/bin/docker-compose 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