Skip to content

Instantly share code, notes, and snippets.

@RadicalZephyr
Created October 10, 2017 02:48
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 RadicalZephyr/94fac2e0ea38476524012becf422968f to your computer and use it in GitHub Desktop.
Save RadicalZephyr/94fac2e0ea38476524012becf422968f to your computer and use it in GitHub Desktop.
Generic systemd service file for running service's with docker-compose
[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service
[Service]
Restart=always
WorkingDirectory=/etc/docker/compose/%i
# Remove old containers, images and volumes
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=/usr/local/bin/docker-compose up
# After Compose
#ExecStartPost=
# Compose down, remove containers and volumes
ExecStop=/usr/local/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