简体   繁体   中英

Docker Container Failing To Start On Boot

I am running an EC2 instance with a startup script that is called on reboot. This startup script checks that the docker daemon is running before then starting the container, but fails with the error: Post http:///var/run/docker.sock/v1.13/containers/create: dial unix /var/run/docker.sock: no such file or directory

Startup Script

# Make sure the docker daemon has started
sudo /usr/sbin/service docker start

# start the container
sudo /usr/bin/docker run -d 91b5261e2dc0

Please note that his is on an ec2 instance where "sudo" does not require password entry.

Crontab entry:

@reboot /bin/bash /home/ubuntu/start-container.sh 2> /home/ubuntu/cron_errors.log

Errors:

start: Job is already running: docker
2014/08/01 09:45:48 Post http:///var/run/docker.sock/v1.13/containers/create: dial unix /var/run/docker.sock: no such file or directory

Whenever I manually run the startup script, it works perfectly which makes it seem like an Environment variable/PATH issue to me. Googling around found information about not setting the DOCKER_HOST, but the startup script works fine even when DOCKER_HOST is still not set.

What do I need to change or define to ensure the container starts correctly on startup?

Versioning Info

OS: Ubuntu 14.04 Hardware Virtualized.

Docker version:

Client version: 1.1.2
Client API version: 1.13
Go version (client): go1.2.1
Git commit (client): d84a070
Server version: 1.1.2
Server API version: 1.13
Go version (server): go1.2.1
Git commit (server): d84a070

uname -a output

Linux ip-10-76-167-92 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

The "solution" ended up being to put in a sleep or a wait after the call to starting the docker daemon. Eg

# Make sure the docker daemon has started
sudo /usr/sbin/service docker start

# Wait for the docker daemon to finish starting
sleep 10

# start the container
sudo /usr/bin/docker run -d 91b5261e2dc0

This appears to be because as Chris McKinnel stated:

...if you take a look inside /etc/init.d/docker, you'll see that calling start uses the --background option to start-stop-daemon which means it's still doing stuff when it returns.

Why not just use && ?

I tried using && to queue the starting of the container after the call to starting the docker daemon, but && will only run the next command if the former was successful which isn't always the case (eg if the docker daemon is already running). [ ref ]

Another solution could be to run this container manually with --restart=always option:

docker run --restart=always -d 91b5261e2dc0    

docker will run start all such containers after docker start and if container will stop without docker stop command.

You can wait for the docker socket to become available before running your container:

# Start the docker daemon
sudo /usr/sbin/service docker start

# Wait for docker socket to become available
while [ ! -e /var/run/docker.sock ]; do sleep 1; done

# start the container
sudo /usr/bin/docker run -d 91b5261e2dc0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM