Skip to content

Instantly share code, notes, and snippets.

@gambolputty
Last active March 30, 2021 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gambolputty/35c7d230e9be11295a19308450371d29 to your computer and use it in GitHub Desktop.
Save gambolputty/35c7d230e9be11295a19308450371d29 to your computer and use it in GitHub Desktop.
docker-compose systemd service

Create a file /etc/systemd/system/myservice.service

Commands

Enable the service:

  • systemctl enable myservice

Then:

  • service myservice start
  • service myservice status
  • service myservice stop
  • etc.

Re-read system config files:

  • systemctl daemon-reload
[Unit]
Description=Service Name
Requires=docker.service
After=docker.service
[Service]
User=username
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/path/to/directory
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment