Upstart script to run container won't manage lifecycle

折月煮酒 提交于 2019-12-03 20:26:30

You should create a named container by running the following command:

docker run --name dtest ubuntu /bin/bash -c "echo Starting;sleep 20;echo Stopping"

Then create the following upstart script (pay attention to the -a flag) which will manage the lifecycle of this container as you expect

start on runlevel [2345]
stop on runlevel [!2345]
respawn
script
  /usr/bin/docker start -a dtest
end script

I would also suggest to add the -r flag to the main docker daemon execution script, so that docker will not automatically restart your containers when the host is restarted (instead this will be done by the upstart script)

sudo sh -c "echo 'DOCKER_OPTS=\"-r=false\"' > /etc/default/docker"

The process of configuring a Docker containers to work with process managers like upstart is described in a great detail here

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