Systemd Service

Template

  • systemd service to run docker-compose

[Unit]
Description=My Systemd Services
Requires=docker.service network-online.target
After=docker.service network-online.target
StartLimitIntervalSec=0

[Service]
WorkingDirectory=<directory of docker-compose>
ExecStartPre=/bin/bash <any pre start script>
ExecStart=/usr/local/bin/docker-compose up
ExecStop=/usr/local/bin/docker-compose down
Restart=always
RestartSec=60

[Install]
WantedBy=multi-user.target

Enable systemd service

  • You can create a file by using the template above accordingly, let say named myssytemd.service

  • Copy the service into /etc/systemd/system and enable it

  • After it is enabled and is started, the service would be running automatically even after the system reboots.

Start systemd service

Stop systemd service

Disable systemd service

Check log of systemd service

Last updated