Skip to content

Instantly share code, notes, and snippets.

@oun
Last active February 24, 2017 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oun/bd1e025ea23fcfc921c2efa38b12e6c5 to your computer and use it in GitHub Desktop.
Save oun/bd1e025ea23fcfc921c2efa38b12e6c5 to your computer and use it in GitHub Desktop.
Jenkins Dockerfile that support docker in docker and Ansible
# https://github.com/axltxl/docker-jenkins-dood/blob/develop/Dockerfile
FROM jenkins:2.19.2
# Install necessary packages
USER root
RUN apt-get update \
&& apt-get install -y sudo supervisor \
&& rm -rf /var/lib/apt/lists/*
# Install docker-engine
# According to Petazzoni's article:
# ---------------------------------
# "Former versions of this post advised to bind-mount the docker binary from
# the host to the container. This is not reliable anymore, because the Docker
# Engine is no longer distributed as (almost) static libraries."
ARG docker_version=1.12.3
RUN curl -sSL https://get.docker.com/ | sh && \
apt-get purge -y docker-engine && \
apt-get install docker-engine=${docker_version}-0~jessie && \
apt-get install -y software-properties-common && \
apt-add-repository ppa:ansible/ansible && \
apt-get install -y ansible
RUN curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# Make sure jenkins user has docker privileges
RUN usermod -aG docker jenkins
# Install initial plugins
USER jenkins
# supervisord
USER root
# Create log folder for supervisor and jenkins
RUN mkdir -p /var/log/supervisor
RUN mkdir -p /var/log/jenkins
# Copy the supervisor.conf file into Docker
#COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Start supervisord when running the container
#CMD /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
@oun
Copy link
Author

oun commented Feb 24, 2017

Build docker image:

docker build -t oun/jenkins .

Please change oun/jenkins to your prefer name and reference this when you run docker container.

Start Jenkins docker

docker run -p 8080:8080 -p 50000:50000 -v /datadisk/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -d oun/jenkins

Where /datadisk/jenkins is the host path map to container jenkins files.
-v /var/run/docker.sock:/var/run/docker.sock set your Jenkins docker to start docker with host docker engine. This is needed for docker in docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment