Work-Adventure/install/Add docker-compose as systemd unit: Difference between revisions

From Technologia Incognita
Jump to navigation Jump to search
Wikinaut (talk | contribs)
Wikinaut (talk | contribs)
m page section layout chg
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
:: → Source: https://gist.github.com/mosquito/b23e1c1e5723a7fd9e6568e5cf91180f
== Docker compose as a systemd unit ==
== Docker compose as a systemd unit ==


Line 35: Line 33:


For <code>/opt/traefik-infra</code> and <code>/opt/workadventure</code> run
For <code>/opt/traefik-infra</code> and <code>/opt/workadventure</code> run
<pre>
<pre>
systemctl start docker-compose@traefik-infra
systemctl start docker-compose@traefik-infra
systemctl start docker-compose@workadventure
systemctl start docker-compose@workadventure
</pre>
</pre>
To have them started automatically after system boot, run once
<pre>
systemctl enable docker-compose@traefik-infra
systemctl enable docker-compose@workadventure
systemctl daemon-reload
</pre>
== More information and discussion ==
* https://gist.github.com/mosquito/b23e1c1e5723a7fd9e6568e5cf91180f

Latest revision as of 11:44, 20 March 2021

Docker compose as a systemd unit

SystemD calling binaries using an absolute path. In my case is prefixed by /usr/bin, you should use paths specific for your environment.

Create a general /etc/systemd/system/docker-compose@.service:

[Unit]
Description=%i service with docker compose
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=true
# for each of your services
# place your .env and docker-compose.yaml files in a subdirectory of the WorkingDirectory
WorkingDirectory=/opt/%i
ExecStart=/usr/bin/docker-compose up -d --remove-orphans
ExecStop=/usr/bin/docker-compose down

[Install]
WantedBy=multi-user.target

Place the docker-compose.yaml and .env files of any of your services (traefik-infra, workadventure ...) in a subdirectory of /opt (example /opt/workadventure) and call

systemctl start docker-compose@yourservice

Example:

For /opt/traefik-infra and /opt/workadventure run

systemctl start docker-compose@traefik-infra
systemctl start docker-compose@workadventure


To have them started automatically after system boot, run once

systemctl enable docker-compose@traefik-infra
systemctl enable docker-compose@workadventure
systemctl daemon-reload


More information and discussion