Last active
August 29, 2017 16:26
-
-
Save noyb34/389e8fb1172d6c07b2e1f634737e42e2 to your computer and use it in GitHub Desktop.
config unit
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
######################################################################## | |
Create file /etc/systemd/system/myservice.service and include below code | |
######################################################################## | |
[Unit] | |
Description=myservice | |
Requires=docker.service | |
After=docker.service | |
[Service] | |
Restart=always | |
User=myuser # Optional | |
WorkingDirectory=/path/working/dir | |
# Remove old containers, images and volumes | |
ExecStartPre=/usr/bin/docker-compose -f my.yml down -v | |
ExecStartPre=/usr/bin/docker-compose -f my.yml rm -v | |
ExecStartPre=-/bin/bash -c 'docker volume rm $(docker volume ls -q)' | |
ExecStartPre=-/bin/bash -c 'docker rmi $(docker images | grep "<none>" | awk \'{print $3}\')' | |
ExecStartPre=-/bin/bash -c 'docker rm -v $(docker ps -aq)' | |
# Compose up | |
ExecStart=/usr/bin/docker-compose -f my.yml up | |
# Compose down, remove containers and volumes | |
ExecStop=/usr/bin/docker-compose -f my.yml down -v | |
[Install] | |
WantedBy=multi-user.target | |
#################################################### | |
systemctl start myservice | |
##################################################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment