Cannot get Jenkins Docker slave to build docker images

I am currently experimenting with Docker in combination with Jenkins to streamline the CI/CD workflow for a new project. I do so on a Mac with Docker 1.12 installed.

This is what I do:

  • Docker: mysql:5.6 container stopping whenever a linked container is removed
  • Flow of registration between kafka and zookeeper
  • Docker Maven Spotify plugin - Possible to switch to non-secure registry
  • Docker and apache2, remove port from url
  • From a container running on Docker for Windows, how can I access a port on the host?
  • Run MySQL on different port with different config
    1. Use docker machine to create a new Docker server
    2. Use the official Jenkins Docker image to spin up a Jenkins instance on that server
    3. Install the “Yet Another Docker Plugin” and “CloudBees Docker Pipeline” plugins.
    4. Add a “Docker Cloud” using the IP of the Docker server above and the third party Docker DinD image tehranian/dind-jenkins-slave

    With this setup, I run a very simple pipeline job like this:

    node('docker') {
        docker.image('hseeberger/scala-sbt').inside {
            stage 'Checkout'
            echo 'We got here!'
        }
    }
    

    Jenkins spins up a Docker instance as expected and executes the job. So the basic Docker setup is working as expected.

    But the Docker command within the job fails. Log output looks something like this:

    [Pipeline] node
    Still waiting to schedule task
    Docker-23ebf3d8dd4f is offline
    Running on Docker-23ebf3d8dd4f in /home/jenkins/workspace/docker-test
    [Pipeline] {
    [Pipeline] sh
    [docker-test] Running shell script
    + docker inspect -f . hseeberger/scala-sbt
    
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?
    [Pipeline] sh
    [docker-test] Running shell script
    + docker pull hseeberger/scala-sbt
    Using default tag: latest
    Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: https://index.docker.io/v1/
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    

    Now when I browse around for solutions, it is usually mentioned that the Docker socket needs to be provided to the container as a volume, but that doesn’t seem to work either.

    Since the general setup seems to be working, wouldn’t the slave simply have to do the same thing as the Jenkins plugin does to spin up the Docker slave in the first place? That is, use the URL of the Docker server to control it? Since I assume this is an extremely common use-case, there must be a Docker image for Jenkins Docker slaves that can do this out of the box, right? What am I missing?

  • Error mounting volumes on Openshift (Next gen)
  • Connecting to postgres from a docker container
  • Docker official registry url
  • Docker-machine resource limit
  • Can't connect to database with docker-compose with mysql and php 7
  • Why can't I “freopen” a “tmpfile”?
  • One Solution collect form web for “Cannot get Jenkins Docker slave to build docker images”

    You might need to set the docker env and use the content of docker-machine env node in your running shellscript.

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