In an effort to become more comfortable with Docker, I will be deploying applications in containers moving forward!
First test subject - Jenkins. What is Jenkins? Jenkins is a CI/CD platform that automates code integrations and deployments. It is written in java and uses port 8080 to communicate to the world.
- Linux virtual machine ( I'm using CentOS 7)
Pull down Jenkins Docker image
According to the Jenkins' docs the recommended image to install is
- Use the
docker pullcommand to pull down the Docker image.
docker pull jenkinsci/blueocean
Create a New Container Based on the Jenkins Image
To create a new container use the
docker run command.
docker run \ --name jenkins \ -u root \ --rm \ -d \ -p 80:8080 \ -p 50000:50000 \ -v jenkins-data:/var/jenkins_home \ -v /var/run/docker.sock:/var/run/docker.sock \ jenkinsci/blueocean
--name jenkins will give the container the name jenkins.
-u root this will run jenkins as root inside of the container.
--rm will delete the container when it is stopped.
-d will run the container in detached mode.
-p 80:8080 will map port 8080 inside of the container to port 80 outside of the container. This will allow us to reach the Jenkins UI using port 80 instead of 8080.
-p 50000:50000 is needed by the blueocean plugin.
-v jenkins-data:/var/jenkins_home will map /var/jenkins_home inside of the container to a docker volume. This will allow the data on Jenkins to persist, in the event the Jenkins docker image get updated.
-v /var/run/docker.sock:/var/run/docker.sock this mapping will allow the container to communicate with the jenkinsci/blueocean image.
2. Check to make sure the Jenkins container is running smoothly with the
docker ps -a command. You will see an output like below:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 24f6a6c4da81 jenkinsci/blueocean "/sbin/tini -- /usr/…" 2 minutes ago Up 2 minutes 0.0.0.0:50000->50000/tcp, 0.0.0.0:80->8080/tcp jenkins
3. Log into the Jenkins UI by using your web browser and going to
4. Follow the prompts in the UI. Create a new user and install default plugins.
Plugin Install Issues
Not sure if I was the only one to encounter this issue, but when I tried to install the greenballs plugin through the UI, Jenkins would become unresponsive. If this ever happens to you, you will need to install the plugin via the command line.
- Download the
jenkins-cli.jarfrom your Jenkins instance.
2. Log into the container.
docker exec -it CONTAINER_ID /bin/bash
3. Use scp to get the file from the host to the container.
scp username@host:/path_to/jenkins-cli.jar .
4. Using the jenkins-cli command to install a plugin.
java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin <name>
The Wrap Up
That is all to it! A fairly painless process, and now Jenkins is running from within a container. If you ever need to update Jenkins just pull down the latest image and then recreate the container.