Skip to content

Instantly share code, notes, and snippets.

@johananl
Last active July 19, 2018 22:12
Show Gist options
  • Save johananl/61ba65b0af7211dfd58ff1d20ec69ee6 to your computer and use it in GitHub Desktop.
Save johananl/61ba65b0af7211dfd58ff1d20ec69ee6 to your computer and use it in GitHub Desktop.
Running a container as a systemd service
# Put this file under /etc/systemd/system/redis.service
[Unit]
Description=Redis Container
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
ExecStartPre=-/usr/bin/docker stop %n
ExecStartPre=-/usr/bin/docker rm %n
ExecStartPre=/usr/bin/docker pull redis
ExecStart=/usr/bin/docker run --rm --name %n redis
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment