In a world of always searching for better ways to make automated deployments more efficient, the industry is constantly looking to improve practices and implement Continuous Integration/Continuous Delivery (CICD). With a tool like Jenkins, it makes deploying software easier than ever before. With a Jenkins server up and running, software can be deployed into a server or a container.
What about if Jenkins itself is software running in a container? In this blog post, you will learn how to create a full-fledged Jenkins server that runs in a container.
To follow along with this post and take a hands-on approach you will need:
- Basic knowledge of what Jenkins is
- Basic knowledge of what Docker is and have used the Docker Command-Line Interface (CLI) before.
- Docker installed on your computer. You can find the Docker installation here for any operating system
Using the Jenkins Image
In this section, you will get a hands-on approach pulling down the Jenkins docker image to your local computer using
docker commands. The image can then be used to create a Jenkins docker container in the upcoming section Running the Jenkins Image to Create a Jenkins Container.
The Jenkins docker image is available on docker hub which you can find here. Jenkins from docker hub is the official image created and maintained by Jenkins.
If you search
jenkinsin docker hub, there will be several different images. Many however may not be maintained by Jenkins.
Open up a terminal and run the following to clone the Jenkins docker image.
docker pull jenkins:latest
The Jenkins image will start downloading to the local computer.
Once the download of the Jenkins image is complete, run the following command to list the Jenkins image.
docker image ls jenkins
The image will show, including the creation date, image ID, and size.
Running the Jenkins Image to Create a Jenkins Container
In the previous section, you learned how to pull down the Jenkins docker image to your local computer. Now you'll create a docker container from the Jenkins image.
Creating the Jenkins Container
To run a Jenkins container based on the downloaded Jenkins image from docker hub, the following command will be run. Before running the command, let's break down the switches.
--name= the name of the newly created container based off of the Jenkins image.
- The first
-pis the port that will be exposed on localhost. This means that you will be accessing the Jenkins UI using something like
localhost:8080. More on this in the upcoming section Accessing the Jenkins UI.
- The second
-p(50000)is the port that will be opened inside of the Jenkins container. This is for network connectivity for you to access the Jenkins UI from outside of the container.
jenkins= the docker image name
docker run --name localjenkins -p 8080:8080 -p 50000:50000 jenkins
Once the above is ran, you will see output on the terminal. The output is Jenkins starting inside of the container.
Accessing the Jenkins UI
In the previous section, you created a container based on the Jenkins docker image. Now you are ready to access the Jenkins UI running on the local machine.
In the terminal, you will see a section similar to the screenshot below. The screenshot below shows a default admin password. The default admin password is needed for accessing the Jenkins UI for the first time. Copy the password so you can use it to sign into Jenkins via the UI.
To access the Jenkins UI, open up a web browser and go to
localhost:8080. You will be presented with an Unlock Jenkins screen. Paste in the password that you copied previously and click the blue Continue button.
Click on the Select plugins to install option.
Click on the None option then click the blue Install button. At this time no plugins need to be installed, which is why you are choosing None to install.
Click the Continue as admin option as shown in the screenshot below.
Click the Start using Jenkins button to access the Jenkins home page.
Congrats! You have successfully created a Jenkins server inside of a docker container.
In this post, you learned how to take Jenkins that ships your containerized software and containerize the platform itself. Containerizing the CICD platform allows for one less infrastructure component that needs to be managed. It allows for fast scalability and innovation in the CICD process in an organization.