k-space-infra-automation/ansible/kanban/templates/systemd_docker-compose_service.j2
2019-11-08 00:46:58 +02:00

26 lines
725 B
Django/Jinja

[Unit]
Description=%i service with docker compose managed by Ansible
Requires=docker.service
After=docker.service
[Service]
Restart=always
WorkingDirectory=/opt/%i
# Remove old containers, images and volumes
ExecStartPre=/usr/bin/docker-compose down -v
ExecStartPre=/usr/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=/usr/bin/docker-compose up
# Compose down, remove containers and volumes
ExecStop=/usr/bin/docker-compose down -v
[Install]
WantedBy=multi-user.target