Skip to content

Instantly share code, notes, and snippets.

@twogood
Created May 8, 2021 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twogood/3ed99fe27e70f3bad3e465deac614931 to your computer and use it in GitHub Desktop.
Save twogood/3ed99fe27e70f3bad3e465deac614931 to your computer and use it in GitHub Desktop.
[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