First create a service file

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

Add to the file the docker compose service like so,

[Unit]
Description=Some personal Docker containers
After=docker.service
Requires=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash -c "docker compose -f /home/cocomac/docker-compose.yml up --detach"
ExecStop=/bin/bash -c "docker compose -f /home/cocomac/docker-compose.yml stop"

[Install]
WantedBy=multi-user.target

Then enable the service

sudo systemctl enable docker-compose

Then start the service

sudo systemctl start docker-compose

Check the status of the service with…

sudo systemctl status docker-compose

Other commands you can run are

  • stop: stops the service
  • restart: stops and starts the service
  • disable: disables the service

Leave a Reply

Your email address will not be published. Required fields are marked *