Skip to content

Instantly share code, notes, and snippets.

@islander
Created March 26, 2020 22:56
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 islander/0d69885fe7fe806eff85a286b738ef97 to your computer and use it in GitHub Desktop.
Save islander/0d69885fe7fe806eff85a286b738ef97 to your computer and use it in GitHub Desktop.

docker-compose as systemd service

$ sudo cp docker-compose@.service /etc/systemd/system
$ sudo systemctl daemon-reload
$ sudo systemctl enable docker-compose@mongodb
$ sudo systemctl start docker-compose@mongodb
[Unit]
Description=%i service with docker-compose
Requires=docker.service
After=docker.service
[Service]
Restart=always
WorkingDirectory=/opt/docker/%i
# Remove old containers, network and volumes
ExecStartPre=/usr/local/bin/docker-compose down -v
ExecStartPre=-/bin/bash -c 'docker network rm %i_'
ExecStartPre=-/bin/bash -c 'docker ps -aqf "name=%i_" | xargs docker rm'
# Compose up
ExecStart=/usr/local/bin/docker-compose up
# Compose down, remove containers
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