Public | Automated Build

Last pushed: a year ago
Short Description
jenkins-dood
Full Description

Jenkins + DOOD (Docker-Outside-Of-Docker)

This Jenkins Docker image provides Dockerish capabilities using Docker-outside-of-Docker (dood), which allows you to run any Docker container in your Jenkins build script. This image creates Docker sibling containers rather than children which would be created if Docker-In-Docker (dind) was used. Some advantages of dood over dind:

  • enables sharing of images with host OS
    • eliminates storing images multiple times
    • makes it possible for Jenkins to automate local image creation
  • eliminate the need for supervisord (which means multiple processes)
  • eliminates a virtualization layer (lxc)
  • allows greater flexibility at runtime
  • permits the jenkins (sudo)user to run docker without the sudo prefix

The final point is specific to this implementation and provides Docker functions within Jenkins workflows.

node {
  def maven = docker.image('maven:latest')
  maven.pull() // make sure we have the latest available from Docker Hub
  sh 'docker run --rm maven mvn --version'
}

Important note: This image uses the latest Docker distribution and the host's Docker installation must be the same version.

This Docker image is based on Continuous Delivery with Docker on Mesos in less than a minute – Part 1, Running Docker in Jenkins (in Docker) , killercentury/docker-jenkins-dind and jpetazzo/dind instead of the offical Jenkins. Morever, Docker Compose is available for launching multiple containers with the CI.

Build this image (from the directory containing the Dockerfile):

docker build -t jenkins-dood .

Run it with mounted directory from host:

docker run -d -p 8080:8080 -v /your/path:/var/lib/jenkins --name jenkins-dood jenkins-dood

Bash function example with additional arguments including:

  • -e "TZ=America/Chicago" sets the timezone
  • -v $HOME/Workspace/.jenkins/.ssh:/var/lib/jenkins/.ssh for sharing your ssh key with the container
  • -v /dev/urandom:/dev/random is to deal with entropy issues
  • -v /var/run/docker.sock:/var/run/docker.sock exposes the Docker daemon socket to this container instead of using dind (Docker In Docker)

A message is displayed showing the Jenkins URL to open in a browser.

jenkins-dood(){
        x11host
        LOCAL_PORT=11080

        docker run -d \
                -e DISPLAY=$X11HOST:0.0 \
                -e "TZ=America/Chicago" \
                -v $HOME/Workspace/.jenkins/.ssh:/var/lib/jenkins/.ssh \
                -v /dev/urandom:/dev/random \
                -v /var/run/docker.sock:/var/run/docker.sock \
                --name jenkins-dood \
                -p $LOCAL_PORT:8080 \
                jenkins-dood
    VBOX_IP=$(docker-machine ip $(docker-machine active))
    echo "Jenkins started at: http://$VBOX_IP:$LOCAL_PORT"
}

The x11_host helper function simply creates an environment variable using the Docker machine's HostOnlyCIDR so the Jenkins container may launch GUI applications. Note: GUI applications will require some additional setup to display on the host.

# Define a variable to use for the X11 host IP
x11host(){
        ACTIVE_MACHINE=$(docker-machine active)
        X11HOST=$(docker-machine inspect $ACTIVE_MACHINE \
                --format={{.Driver.HostOnlyCIDR}} \
                | cut -d'/' -f1)
}

Example output from above run within a bash function named 'jenkins-dood'

$ jenkins-dood
jenkins-dood
569ba93cd7d69a654bcdb97874ea6aa95025a74d4ae92fcb3e620c23676c4d12
Jenkins started at: http://192.168.99.101:11080
$

Refer to psharkey/novnc for an alternative X11 configuration.

Docker Pull Command
Owner
yelisheng1984
Source Repository

Comments (0)