huberm
12/28/2017 - 7:55 PM

[docker-compose systems setup] #docker

[docker-compose systems setup] #docker

Running docker-compose under systemd

  1. Place the systemd unit files in /etc/systemd/system
  2. Create each docker-compose in a subdir under /usr/local/docker/
  3. Enable the cleanup service:
systemctl enable docker-compose.timer
  1. For each of your docker-compose applications, enable and start it. For example, to start the app in /usr/local/docker/traefik:
systemctl enable docker-compose@traefik
systemctl start docker-compose@traefik
[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service

[Service]
Restart=always

WorkingDirectory=/usr/local/docker/%i

#remove our old containers
ExecStartPre=/usr/bin/docker-compose down -v
ExecStartPre=/usr/bin/docker system prune


ExecStart=/usr/bin/docker-compose up

ExecStop=/usr/bin/docker-compose down -v

[Install]
WantedBy=multi-user.target
[Unit]
Description=Docker cleanup timer

[Timer]
OnUnitInactiveSec=12h

[Install]
WantedBy=timers.target
[Unit]
Description=Docker cleanup
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
WorkingDirectory=/tmp
User=root
Group=root
ExecStart=/usr/bin/docker system prune -f

[Install]
WantedBy=multi-user.target