First execution of Docker on a new EC2 Jenkins Slave does not work

I’m using the EC2 Plugin in Jenkins to spin up slave instances when we need them. Recently I’ve wanted to play around with Docker so I installed it on the AMI we use as a slave – but the first run on the slave never seems to work.

+ docker ps
time="2015-04-17T15:38:20Z" level="fatal" msg="Get http:///var/run/docker.sock/v1.16/containers/json: dial unix /var/run/docker.sock: no such file or directory. Are you trying to connect to a TLS-enabled daemon without TLS?" 

Any runs after this seem to work – why won’t the slave work on the first job? I’ve tried using sudo, executing docker ps before docker build but nothing seems to fix the problem.

  • How to install zless in alpine linux?
  • Getting list of running containers from a cluster
  • How to know which docker image I am using here?
  • Can't change directories in a docker container?
  • Gcloud kubernetes/docker deploy works but stops responding after 10 minutes
  • What's the best way to compose multiple Docker images with different bases
  • What is the difference b/w “service docker start” and “docker -d”?
  • Access Docker container /home folder on host
  • Vagrant unable to connect to docker through ssh
  • How to use awslog driver in to get the logs from the docker container?
  • Can I run DCE (Docker Container Executor) on Yarn with Kerberos?
  • How to remote access(from out net) to jupyter notebook running on docker on ubuntu server
  • One Solution collect form web for “First execution of Docker on a new EC2 Jenkins Slave does not work”

    The problem is that Jenkins is just waiting for the slave to respond to an SSH connection, not that Docker is running.

    To prevent the slave from becoming “online” too quickly, put a check in the “Init Script” section in the EC2 Slave Plugin configuration section. Here’s an example of the one I use against the base AMI.

    while [[ -z $(/sbin/service docker status | grep " is running...") &&  $sleep_counter -lt 300 ]]; do sleep 1; ((sleep_counter++)); echo "Waiting for docker $sleep_counter seconds - $(/sbin/service docker status)"; done
    

    Amazingly, it can take up to 60 seconds between the slave coming up and the Docker service starting, so I’ve set the timeout to be 5 minutes.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.