docker-compose and Jenkins

In this tutorial i show an example, how to install Jenkins (version 2.0) via docker-compose (and docker-machine).

Preconditions

Preparation

# create example directories
$ mkdir -p ~/Projects/Example/Jenkins_HOME && cd ~/Projects/Example

# create new and edit compose files
$ vim docker-compose.yml
---
version: '2'
services:
  jenkins:
    image: jenkins:2.0
    container_name: jenkins
    restart: always
    ports:
      - 8080:8080
    volumes:
      - ./FOR_JENKINS:/var/jenkins_home

Build and run

# create new VM
$ docker-machine create -d virtualbox --virtualbox-memory "2048" example-vm

# point shell
$ eval $(docker-machine env example-vm)

# show current state
$ docker-machine ls
...
NAME         ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
example-vm   *        virtualbox   Running   tcp://192.168.99.100:2376           v1.11.0 

# run docker-compose
$ docker-compose up -d

# show state
$ docker-compose ps
...
Name                Command               State                 Ports               
------------------------------------------------------------------------------------
jenkins   /bin/tini -- /usr/local/bi ...   Up      50000/tcp, 0.0.0.0:8080->8080/tcp

# get administrator password
$ docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword

Run Browser

docker jenkins container