Skip to content

Instantly share code, notes, and snippets.

@skomma
Last active November 6, 2017 01:59
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 skomma/c4514e84b6a1dcd22d31516f7acc9c2e to your computer and use it in GitHub Desktop.
Save skomma/c4514e84b6a1dcd22d31516f7acc9c2e to your computer and use it in GitHub Desktop.
template unit file for using docker-compose
# This file is the systemd template unit for using docker-compose
#
# Usage:
# 1. place docker-compose yaml file (ex. /etc/docker-compose/jenkins/docker-compose.yml)
# 2. copy this file to /etc/systemd/system/docker-compose@.service
# # curl https://gist.githubusercontent.com/skomma/c4514e84b6a1dcd22d31516f7acc9c2e/raw/8eacc7b62e8a7f170153cfa41338d67b822f95b4/docker-compose@.service -o /etc/systemd/system/docker-compose@.service
# 3. run "systemctl start docker-compose@jenkins.service"
# (If you want to start automatically at boot time, run systemctl enable docker-compose@jenkins.service)
[Unit]
Description=Docker-compose managed containers
After=docker.service
[Service]
WorkingDirectory=/etc/docker-compose/%i
ExecStart=/usr/local/bin/docker-compose up
ExecStop=/usr/local/bin/docker-compose down
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
@ryu-sato
Copy link

ryu-sato commented Nov 4, 2017

停止時に docker network などを開放するため、停止時の操作を追加してみてはどうでしょう?

[Service]
WorkingDirectory=/etc/docker-compose/%i
ExecStart=/usr/local/bin/docker-compose up --no-recreate
ExecStop=/usr/local/bin/docker-compose down
KillSignal=SIGINT

@skomma
Copy link
Author

skomma commented Nov 4, 2017

確かに。
もはや、volume はコンテナ紐付きではないので、それでいいのかも。
ついでに、 --no-recreate ももはや無用なので、消す。

@ryu-sato
Copy link

ryu-sato commented Nov 6, 2017

対応ありがとう!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment