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.

  • Simple PHP-CLI Cron Supervisor Docker not working
  • Does Meteor up (MUP) works exactly as Docker Automated Builds?
  • Unable to connect to remote MySQL from a docker on Ubuntu Desktop
  • Kubernetes - dynamic provisioning of storage
  • Docker with both Jar and Gradle executions in it for jenkins
  • Error when building a Docker container
  • Is there a straight way to get html response from a unix socket in Go (like curl does)?
  • docker: command not found ( mac mini ) only happens in jenkins shell step but work from command prompt
  • Where to put ebextensions config in AWS Elastic Beanstalk Docker deploy with dockerrun source bundle?
  • MobileFirst Container CLI Extensions are not installed
  • Deploy Django app with Docker
  • docker container port format does not looks right(like <port>-<port>)
  • 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.