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

From Technologia Incognita
Jump to: navigation, search
(Docker compose as a systemd unit)
(Docker compose as a systemd unit)
Line 5: Line 5:
 
SystemD calling binaries using an absolute path. In my case is prefixed by <code>/usr/bin</code>, you should use paths specific for your environment.
 
SystemD calling binaries using an absolute path. In my case is prefixed by <code>/usr/bin</code>, you should use paths specific for your environment.
  
Create <code>/etc/systemd/system/docker-compose@.service</code>:
+
Create a general <code>/etc/systemd/system/docker-compose@.service</code>:
  
 
<pre>
 
<pre>
Line 16: Line 16:
 
Type=oneshot
 
Type=oneshot
 
RemainAfterExit=true
 
RemainAfterExit=true
WorkingDirectory=/opt/docker/compose/%i
+
# 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
 
ExecStart=/usr/bin/docker-compose up -d --remove-orphans
 
ExecStop=/usr/bin/docker-compose down
 
ExecStop=/usr/bin/docker-compose down
Line 24: Line 26:
 
</pre>
 
</pre>
  
Place your <code>docker-compose.yaml</code> and <code>.env</code> files into <code>/opt/docker/compose/myservice</code> and call
+
Place the <code>docker-compose.yaml</code> and <code>.env</code> files of any of your services (traefik-infra, workadventure ...) in a subdirectory of <code>/opt</code> (example <code>/opt/workadventure</code>) and call
  
 
<pre>
 
<pre>
systemctl start docker-compose@myservice
+
systemctl start docker-compose@yourservice
 +
</pre>
 +
 
 +
Example:
 +
 
 +
For <code>/opt/traefik-infra</code> and <code>/opt/workadventure</code> run
 +
 
 +
<pre>
 +
systemctl start docker-compose@traefik-infra
 +
systemctl start docker-compose@workadventure
 
</pre>
 
</pre>

Revision as of 03:59, 20 March 2021

→ Source: https://gist.github.com/mosquito/b23e1c1e5723a7fd9e6568e5cf91180f

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