Table of Contents
Installing Docker on Jenkins
Jenkins is a great tool to build and package artifacts, it can be either deployed independently as a service in docker, lets go through the steps required to install Jenkins on docker as a container.
In this tutorial, we will
- Get Jenkins Docker Image from Docker Hub
- Run the Docker Image
- Configure Jenkins
Get official Jenkins Image
- Go to your terminal/command prompt and get the Jenkins latest’s image from docker hub
123docker pull Jenkins
Run Docker Image
Map localhost ports
- Then we will try to run the image, we will map Jenkins on localhost port 8080 and port 50000
Port 8080 exposes the web interface and port 50000 gives you access to a remote Java (JIRA) API.
Map Volumes to persist data
- If it is important to persist the Jenkins data you can choose between the 2 options.
- Save data within the docker container, the docker volume persists upon restarts and even after if the container is deleted.
- Save data on your host/disk/laptop/machine. Weigh in your requirements and see what fits in with your requirements.
- Option-1> To persist the data within docker container
1234docker volume create --name jenkins_datadocker run --name jenkins -d -v jenkins_data:/var/jenkins_home -p 8080:8080 -p 50000:50000 jenkins:latest
- Option-2>To persist the data within host( host machine/laptop) container(option-2)
123docker run --name jenkins -d -v /Users/jenkins:/var/jenkins_home -p 8080:8080 -p 50000:50000 jenkins:latestDon’t forget to change the path to your local drive after -v tag /Users/…. in case of Mac and C:/Users…. in case of Windows)
Check Jenkins is running
- Check if docker container Jenkins is running
123docker ps -a
If all is fine, it should show output like below
1234CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES041465f0254e jenkins:latest "/bin/tini -- /usr..." 43 hours ago Up 58 seconds 0.0.0.0:50000>50000/tcp, 0.0.0.0:8082->8080/tcp jenkins
- Go to Jenkins -> Globals tools configurations and add Java/GIT/Maven installations; download from the internet is an option which you can choose if there are no available installations on your disk as shown below.