Reputation: 12754
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
Upvotes: 4
Views: 10540
Reputation: 22482
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
Upvotes: 1
Reputation: 22680
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.
Upvotes: 3
Reputation: 12754
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 ]
Upvotes: 4