How to Install Jenkins on a Docker container


Jenkins is an open-source automation server that helps in automating parts of software development, specifically tasks related to building, testing, and deploying code. It is widely used in continuous integration (CI) and continuous delivery (CD) pipelines.

For us, Mulesoft Architects and Developers, Jenkins is a very important tool, as it can help us in the automation of the Continuous Integration (CI) and Continuous Deployment (CD) processes of our Mule apps.

The best way to learn Jenkins is by doing and trying, and for that a great option is to install your local instance of Jenkins. We can install Jenkins locally in a VM or, even easier, we can install it on a Docker container. 
In this post, we will see how to install Jenkins on a Docker container and how to complete the installation process.

Prerequisites

In terms of software installed, the only prerequisite is to have Docker in your VM or your laptop, wherever you want to keep your local Jenkins. 
If you don't have Docker installed on your OS please install it. Follow this guide to learn how to install Docker on Ubuntu.

Check your firewall or security settings for your VM hosting Docker. Your VM ne
eds to accept traffic on two ports. In this example, we'll use 8080 and 50000. More details later on this post.

Running the container

First, we need to download the Jenkins image (Check out the official Jenkins repository to get the latest version)
docker pull jenkins/jenkins:lts-jdk17

To r
un the container we just need the following command:
docker run -d --name gon-jenkins -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-jdk17

Where:
  • --name gon-jenkins: Provides a name for our jenkins container
  • -d: to run the container in the background
  • -p 8080:8080 maps the port 8080 in the host to the port 8080 in the container. This is the port that Jenkins uses for the web UI management console
  • -p 50000:50000: maps the port 50000 in the host to the port 50000 in the container. Jenkins uses this port for the Jenkins agent.
  • -v jenkins_home:/var/jenkins_home: Creates a dedicated volume for Jenkins data. All Jenkins data will be stored in the /var/jenkins_home folder in the container. It’s always recommended to use a dedicated volume over a bind mount.
  • jenkins/jenkins:lts-jdk17: the jenkins image
To verify the jenkins container is running type the following:
docker ls



Complete the Installation

The first time you start Jenkins you’ll be required to provide an initial password for the admin user. You can find the password in the container logs by running:
docker logs [CONTAINER_ID]


Open a web browser and go to http://localhost:8080


Provide the password we copied from the logs in the previous step


These plugins are generally useful, so click the Install suggested plugins button. The installation might take some minutes.


Once it’s done you’ll be prompted to create the first Admin User. Provide the details of your Admin user and Click Save and Continue


And lastly, you’ll need to confirm the URL of your Jenkins server. In this case, since we’re running it locally on a Docker container it will be http://localhost:8080


Click Save and Finisth and your Jenkins will be ready


Click on Start using Jenkins and you’ll get to the Jenkins homepage

Previous Post Next Post