15

Using instructions for Docker auto-start on Linode VPS running Ubuntu 12.04 and Docker 0.8.1, the specified container does not start on reboot.

Once booted, I am able to

~$ sudo start [service-name]

and everything goes as planned, but I would also like to container to restart after a reboot.

Is the script in the tutorial not designed to handle reboots?

/etc/default/docker file contains one line:

DOCKER_OPTS="-r=false"

/etc/init/service-name.conf is straight from the docker page:

description "service description"                                                                                                            
author "me"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
    # Wait for docker to finish starting up first.
    FILE=/var/run/docker.sock
    while [ ! -e $FILE ] ; do
        inotifywait -t 2 -e create $(dirname $FILE)
    done
    /usr/bin/docker start -a db5e61a9afa8
end script
1
  • 2
    What are the contents of your upstart script and /etc/default/docker? Commented Mar 7, 2014 at 14:10

5 Answers 5

6

At some point over the past couple of months, the upstart script in the tutorial was changed to remove the loop to wait for docker to start. I removed the loop from my upstart scripts and my containers now restart correctly after a reboot.

My /etc/init/service-name.conf script now looks like this:

description "service description"                                                                                                            
author "me"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
    /usr/bin/docker start -a db5e61a9afa8
end script

I'm not sure what was wrong with that loop. Maybe it was pointing to the wrong file on my system, although I didn't make any changes to the default docker install. For now, I'm just happy the fix involved code removal instead of some complicated work-around.

2
  • It'd be more upstart-ish to change the docker job to emit a signal (docker-started) and have that signal trigger the container jobs to start.
    – MikeyB
    Commented May 4, 2014 at 18:00
  • You cannot stop the container this way by issuing command stop service-name. I am facing this issue :( Commented Jul 4, 2014 at 22:19
3

For anyone using ubuntu 14.04 apt-get flavor of docker. You just need to change the startup script to wait on "docker.io" and not "docker" like so:

description "Docker startup script for yum_repo"
author "me"
start on filesystem and started docker.io
stop on runlevel [!2345]
respawn
script
  /usr/local/bin/docker start -a yum_repo_run
end script
1

I am using Ubuntu 13.10 as the host and I had the same issue. I found that docker installs a rc script for docker in /etc/init.d/docker and at the same time installs an upstart script at /etc/init/docker.conf. I just had to remove the rc script /etc/init.d/docker for this issue to go away.

Hope this works for you as well.

1
  • Sadly, this one did not work for me.
    – jody
    Commented Apr 16, 2014 at 0:56
0
DOCKER_OPTS="-r=false"

This means: Don't restart previously running containers.

Remove the -r option or change it to true.

1
  • 2
    Right, but the point is to have upstart handle container restarts, not the docker daemon. If the docker daemon starts the container on reboot, the process can't be managed by upstart.
    – jody
    Commented May 4, 2014 at 14:55
0

/var/run/docker.sock is a socket so you need to use -S when testing for existence:

FILE=/var/run/docker.sock
while [ ! -S $FILE ] ; do
    inotifywait -t 2 -e create $(dirname $FILE)
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .