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

假如想象 提交于 2019-12-03 02:37:02

问题


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.


回答1:


CoreOS uses systemd to manage long running services:

  • https://coreos.com/os/docs/latest/getting-started-with-systemd.html



回答2:


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.




回答3:


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




回答4:


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.




回答5:


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).




回答6:


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.



来源:https://stackoverflow.com/questions/18786054/how-to-auto-restart-a-docker-container-after-a-reboot-in-coreos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!