~Installing Jenkins with Docker ~

Asonti Ginn
Women in Technology
6 min readJul 5, 2023

--

Today's Goals

~ Create a volume for our Jenkins image to persist its data.

~ Create a container using the new volume.

~ Retrieve the Admin password and create a new Jenkins user.

~ Create a new container to verify the new user has been created successfully.

Key Terms

~ Docker: With docker you can build, update, and run containers.

~ Container: A container is made from an image, and it packages up code so it can run quickly in other environments.

~ Jenkins: Jenkins is an open source web server that can be used for automation. This is considered a continuous integration tool.

~ Volume: Dockers own type of file system, there are 2 types of volumes.

~~Named Volume: These have a name that you specify in a command and can be used with multiple containers.

~~Anonymous Volume: These are randomly named by docker and mounted to your container.

~ Sudo: Allows you to run commands as if you are the root user in a terminal.

Docker Benefits

~ Scalability: If there is an increase in traffic you can scale to handle more traffic by running multiple containerized apps.

~ Version Control: Since Containers are made from images, we can have different image versions that we can go back to if needed.

~ Portability: Makes it easier to be moved through different stages and environments.

Prerequisites

~ A docker environment. If you do not have one, check out my article to help set up one. setting-up-docker

~ Basic command line knowledge.

Container Creation

Before we can get the ball rolling, we need to pull our Jenkins image. If you check Docker Hub for Jenkins, you will see that Jenkins had been deprecated. We cannot use the supported tags but instead we need to use jenkins/jenkins.

So, let's pull our Jenkins image. Run the following command.

sudo docker pull jenkins/jenkins

Since your image has downloaded, we now want to find out what port our image uses.

sudo docker inspect jenkins/jenkins

After running that command data should be printed in your terminal. Find the “ExposedPorts”. You can see we have 2 ports 8080 and 50000, these will be the two ports we list when we run our container.

Now that we have obtained the port numbers, we can start the creation of our container. In the command we will run we will also create our own volume that will hold our containers data. I will give a small break down of our command to run our container.

~ -it: This allows you to interact insides the container.

~ -d: This means that the container will run in the background.

~ -p 8080:8080 This specifies the port number; in this case we have 2 ports.

~ -v jenkins:/var/jenkins_home: This is our volume; we are creating our own volume. Before the colon represents the name of the volume. After the colon represents the location of the volume.

sudo docker container run -d -it -p 8080:8080 -p 50000:50000 -v jenkins:/var/jenkins_home jenkins/jenkins

Let's check our volumes, you should see the name of the volume we made in the command above.

sudo docker volume ls

Now check to make sure your container is running correctly.

sudo docker container ls

Signing into Jenkins

Time to load up our webpage. You can input your IP address or type localhost into your browser.

You should see the Jenkins webpage.

As you can see Jenkins is asking for an Administrator Password, we need to return back to our terminal and retrieve the password.

In the screenshot above and on your unlock Jenkins webpage, it states that we can get the password from the /var/jenkins_home/secrets/initialAdminPassword file. Let's cat out this file, in the terminal paste this command, this will provide you with the Administrator Password.

sudo docker exec <CONTAINERID> cat /var/jenkins_home/secrets/initialAdminPassword

Return back to your browser and enter the password.

After unlocking Jenkins, you should be given the option to customize and install Jenkins. To make this easy select Install suggested plugins and it will begin to install everything you need automatically.

Create the admin user, for this section I used my own personal information. You want to make sure you memorize this information. We will not use this login again during this process, but you may need it for yourself.

The next step that appears on your screen please skip.

After skipping the last step your Jenkins should be ready to go.

Create User

Once your Jenkins has loaded to your dashboard it is now time to create our user. We need to go to manage Jenkins.

In manage Jenkins you will find a lot of options, but we only need to create a user. Under security find ‘Users’ and then Create a user.

For security purposes I will not display a picture of the next step but customize your user to your liking. Be sure to remember the username and password, we will be logging in with this user.

After adding the new user, you should see both your users displayed in the user screen.

New Container

We want to create another container to make sure the user we created in Jenkins, is available in another container.

In order to start running another container on the same ports we need to stop the first container we created.

sudo docker container stop <CONTAINERID>

We will run a similar command as last time but this time we will put a name tag. This tag allows you to name your container instead of receiving an auto generated name.

sudo docker container run -d -it -p 8080:8080 -p 50000:50000 --name <INSERTANAME> -v jenkins:/var/jenkins_home jenkins/jenkins

To be sure you used the correct volume, check your volumes there should be no new volumes.

sudo docker volume ls

Now verify your new container is running.

sudo docker container ls

Verify the User

We now want to check and make sure our user we created earlier is available to use. Open a new browser and add your IP. The sign in page should load up.

Sign into Jenkins with the Username and Password I told you to remember.

Once you sign in you should see you are now logged in as the newly created user!

For more, easy to follow articles, follow me on Medium!

--

--

Asonti Ginn
Women in Technology

Hey! I am taking you on my Cloud engineering journey with easy to follow, how-to articles. All provided with an under 10-minute read and PLENTY of pictures!☁️