Jenkins Setup on Docker

Install

apt-get install nginx

replace /etc/nginx/sites-available/default by the following:

# Default server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #


    location / {
            proxy_pass http://127.0.0.1:8080;
        }
}

docker pull jenkins

create /data/jenkins and execute chown 1000 /data/jenkins (1000 is the user id that runs jenkins inside the docker container)

After starting the docker container, you can retrieve the initial password like:

docker exec jenkins-<version> cat /var/jenkins_home/secrets/initialAdminPassword

Start

run docker container as daemon in the background: -d

docker run --name=jenkins-<version> -d -p 8080:8080 -p 50000:50000 -v /data/jenkins:/var/jenkins_home jenkins

Change

Currently not working, see https://github.com/jenkinsci/docker/issues/326

Connect to the latest docker image:
docker run -ti -u root jenkins:latest /bin/bash
Then make your changes, exit, find it
docker ps -a
and commit the image with your custom name
docker commit 72362a6649d1 jenkins:1.7.2_php

Working:

Create a Dockerfile:

FROM jenkins
# if we want to install via apt
USER root
RUN apt-get update && apt-get install -y php5-cli
USER jenkins

or

FROM jenkins
# if we want to install via apt
USER root
RUN apt-get update && apt-get install -y \
    libmysqlclient-dev \
    php5-cli \
    php5-curl \
    python-setuptools \
    python-dev \
    build-essential \
    libssl-dev \
    libffi-dev \
    python3 \
    python3-setuptools \
    python3-dev \
    python-mysqldb

RUN easy_install pip
RUN pip install virtualenv

USER jenkins

Build the image:
docker build -t jenkins:1.7.2_php .
Then start normally using the new tag
docker run --name=jenkins-1.7.2 -d -p 8080:8080 -p 50000:50000 -v /data/jenkins:/var/jenkins_home jenkins:1.7.2_php

Upgrade

docker stop <id-of-old-container>
docker rm <id-of-old-container>
docker pull jenkins

Shortcuts

Remove all containers
docker rm $(docker ps -a -q)