docker-compose systemd

If you want to start your docker container with the boot of the system you can use the systemd function in your Ubuntu System.

First you have to find the path to your docker-compose installation. Use the „which“ command.

which docker-compose

Then you get the path to your installation: in this example: /usr/bin/docker-compose

Now you can create the .service file by using:

sudo nano /etc/systemd/system/docker-compose-app.service

Here we need following content:
But you have to adapt some parts for your installation:
– /usr/local/bin/docker-compose -> to the path of you got earlier with the which command
– /srv/docker -> with the path to your docker-compose.yml file

# /etc/systemd/system/docker-compose-app.service

[Unit]
Description=Docker Compose Application Service
Requires=docker.service
After=docker.service

[Service]
WorkingDirectory=/srv/docker
ExecStart=/usr/local/bin/docker-compose up
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0
Restart=on-failure
StartLimitIntervalSec=60
StartLimitBurst=3

[Install]
WantedBy=multi-user.target

Now save the file and use following command to enable the service at the next reboot:

sudo systemctl enable docker-compose-app

Some helpful commands:

systemctl status docker-compose-app
systemctl start docker-compose-app
systemctl stop docker-compose-app
systemctl restart docker-compose-app

Default config I use:

# /etc/systemd/system/docker-compose-app.service

[Unit]
Description=Docker Compose Application Service
Requires=docker.service
After=docker.service

[Service]
WorkingDirectory=/volume1/docker/wireguard
ExecStart=/usr/bin/docker-compose up
ExecStop=/usr/bin/docker-compose down
TimeoutStartSec=0
Restart=on-failure
StartLimitIntervalSec=60
StartLimitBurst=3

[Install]
WantedBy=multi-user.target

Thanks to:

https://stackoverflow.com/questions/43671482/how-to-run-docker-compose-up-d-at-system-start-up

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Time limit is exhausted. Please reload the CAPTCHA.

Durch die weitere Nutzung der Seite stimmst du der Verwendung von Cookies zu. Weitere Informationen

Die Cookie-Einstellungen auf dieser Website sind auf "Cookies zulassen" eingestellt, um das beste Surferlebnis zu ermöglichen. Wenn du diese Website ohne Änderung der Cookie-Einstellungen verwendest oder auf "Akzeptieren" klickst, erklärst du sich damit einverstanden.

Schließen