Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Container Failing To Start On Boot

Tags:

docker

startup

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
like image 325
Programster Avatar asked Feb 12 '23 08:02

Programster


2 Answers

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

# 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 (e.g. if the docker daemon is already running). [ ref ]

like image 179
Programster Avatar answered Feb 27 '23 17:02

Programster


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.

like image 21
ISanych Avatar answered Feb 27 '23 17:02

ISanych