Upstart script to run the container will not control the life cycle

I have an upstart script (say /etc/init/dtest.conf )

 start on runlevel [2345] stop on runlevel [!2345] respawn script DID=$(docker.io run -d ubuntu /bin/bash -c "echo Starting;sleep 20;echo Stopping") docker.io attach $DID end script 

When launch start dtest is released, the correct cycle "Start ... Stop" forever start dtest in the dropdown logs.

However, if I stop dtest , it means that it crashes correctly, but the container will work for the remaining sleep time (as evidenced by the launch of docker.io ps every second).

Should there be an easy way to launch a docker image in a container with an upstart and manage its life cycle?

My ideal script would be something like this:

 start on runlevel [2345] stop on runlevel [!2345] respawn exec docker.io run -d ubuntu /bin/bash -c "echo Starting;sleep 20;echo Stopping" 

Environment:. This is on AWS using Ubuntu 14.04 on T2.micro, with apt-get install -y docker.io being the only one installed

+2
source share
1 answer

You must 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 (note the -a flag) that will control the life cycle 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 also suggest adding the -r flag to the daemon of the main docker script, so that the docker will not automatically restart your containers when the host restarts (instead, it will be executed by the script bounce)

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

The process of setting up Docker containers to work with process managers such as upstart is described in detail here.

+3
source

Source: https://habr.com/ru/post/972608/


All Articles