Difficulty: Intermediate
Estimated Time: 15-20 minutes

This course will introduce you to the concepts of running a dockerized Jenkins environment. It will spin up a vanilla instance of a Jenkins master server along with a Jenkins build agent. It will introduce you to running docker-compose commands to start Jenkins.

Jenkins+Docker Introduction

Step 1 of 2

Manual Container Orchestration

Manual container orchestration

Lets create some Jenkins containers!

In this step we will pull the Jenkins images and run them manually. The Dockerfile for the Jenkins master image can be found here: https://github.com/jenkinsci/docker/blob/master/Dockerfile-alpine

docker pull jenkins/jenkins:lts-alpine

Lets take a look at that docker image:

docker images | grep --color -E '^|jenkins/jenkins'

mkdir -p /jenkins/data \ && cd /jenkins

docker run -d \ --name jenkins-master \ -u root \ -v /jenkins/data/jenkins-master:/var/jenkins_home \ -p 8080:8080 -p 50000:50000 \ jenkins/jenkins:lts-alpine

Check the Running Container

Lets take a look at the running containers:

docker ps -a | grep --color -E '^|jenkins/jenkins:lts-alpine'

We can even look at the logs of our Jenkins master:

docker logs -f jenkins-master

Exit the log tail by typing ^C

Jenkins User Interface (UI)

Navigate to the Jenkins UI here: https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/ to see the setup wizard. By default the Jenkins docker image creates an admin user to do the initial configuration of your Jenkins server. The password can be found inside the container. To display that password run the following command:

docker exec -t jenkins-master cat /var/jenkins_home/secrets/initialAdminPassword

If we wanted to start up a Jenkins agent, we could run the following command:

docker run -d \ --name jenkins-agent \ -u root \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /jenkins/data/jenkins-agent:/home/jenkins/ci-agent \ jenkins/slave:alpine \ java -jar /usr/share/jenkins/slave.jar -jnlpUrl http://[[HOST1_IP]]:8080/computer/docker-agent/slave-agent.jnlp -secret "changeme" -workDir "/home/jenkins/ci-agent"


docker stop jenkins-master && docker rm jenkins-master

docker stop jenkins-agent && docker rm jenkins-agent

docker ps -a


So far we have manually created two containers using the docker run command, next we will use docker-compose to defined the desired state of our docker containers and let it manged pulling and running the containers.

Terminal Host 2