Running docker app as a system service

Last modified on 2019.07.21

Author: Erik Maier

Step 1

In the /etc/systemd/system directory create a docker-app.service file

[Unit]
Description=App Daemon
After=docker.service
Requires=docker-app.service

[Service]
User=app
Group=docker
Restart=on-abnormal
TimeoutStartSec=300

ExecStartPre=/usr/local/bin/docker-compose -v
ExecStart=/usr/local/bin/docker-compose -f /home/projects/docker-app/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose  -f /home/projects/docker-app/docker-compose.yml down

[Install]
WantedBy=multi-user.target

Step 2

Enable / disable the new docker-app service. If enabled this docker container app will be started after the docker service.

sudo systemctl enable docker-app

sudo systemctl disable docker-app

Step 3

Start / stop your new service

service docker-app start

service docker-app stop