Skip to content

Instantly share code, notes, and snippets.

@gwire
Created October 3, 2021 00:26
Show Gist options
  • Save gwire/912c499a59327beff70b9beb323c1233 to your computer and use it in GitHub Desktop.
Save gwire/912c499a59327beff70b9beb323c1233 to your computer and use it in GitHub Desktop.
Example systemd service for a docker container
[Unit]
Description=Example Container
After=docker.service
Wants=
Requires=docker.service
StartLimitIntervalSec=20
StartLimitBurst=3
[Service]
TimeoutStartSec=0
Restart=always
RestartSec=5
SyslogIdentifier=%N
ExecStartPre=-/usr/bin/docker stop %N
ExecStartPre=-/usr/bin/docker rm %N
ExecStartPre=/usr/bin/docker create --publish 127.0.0.1:9080:80 --name %N example
ExecStart=/usr/bin/docker start -a %N
ExecStop=/usr/bin/docker stop %N
ExecStopPost=-/usr/bin/docker rm %N
## some containers will return status=137 SIGKILL on a normal stop
SuccessExitStatus=137
[Install]
WantedBy=multi-user.target
WantedBy=docker.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment