Richard
Richard

Reputation: 10628

How to auto restart a Docker container after a reboot in CoreOS?

Assuming the Docker daemon is restarted automatically by whatever init.d or systemd like process when the OS is restarted, what is the preferred way to restart one or more Docker containers? For example I might have a number of web servers behind a reverse proxy or a database server.

Upvotes: 41

Views: 29865

Answers (6)

docwhat
docwhat

Reputation: 11704

The only documentation I've seen is Docker's Host Integration docs which are a bit light on details, etc.

Basically, it suggests starting the daemon with -r=false and using systemd (or upstart if you're using something other than CoreOS).

Upvotes: 1

Mark O'Connor
Mark O'Connor

Reputation: 77961

CoreOS uses systemd to manage long running services:

Upvotes: 14

Frank Wong
Frank Wong

Reputation: 1826

For people want to auto restart a docker container, but didn't specify --restart flag (default to 'no') while running it, you can use docker update command to add one of the following three other options:

  • on-failure
  • unless-stopped
  • always

See this post for the details. People have problem with always restart flag on, can consider using either on-failure or unless-stoppedoption.

Upvotes: 2

czerasz
czerasz

Reputation: 14250

Used Restart and RestartSec to make it work:

# Restart after crash
Restart=on-failure
# Give the service 10 seconds to recover after the previous restart
RestartSec=10s

View the documentation.

Upvotes: -1

hani elabed
hani elabed

Reputation: 830

What worked for me is to add --restart='always' to the container {run -d ...} command

Upvotes: 14

creack
creack

Reputation: 121502

if you start the daemon with docker -d -r, it will restart all containers that were running prior the daemon stopped. This will become the default behavior in the next release.

Upvotes: 34

Related Questions