In this tutorial, I will guide you how to install Jenkins server using Docker.
First, open the Terminal on macOS and Linux or the Console on Windows, then use the “docker pull” command to download the Jenkins Image from the Docker Repository.
Here, we have two versions of Jenkins:
- One is the LTS version (Long-term Support): This version is stable.
- Secondly, the Weekly version is built and pushed to the Docker Repository weekly.
To download the LTS version, use the following command:
1 |
docker pull jenkins/jenkins:lts |
As for the Weekly version, use the following command:
1 |
docker pull jenkins/jenkins |
In this tutorial, I will use the Weekly version.
Result:
After downloading Jenkins Image, I will now launch a container from this image.
The command to start the container is as follows:
1 |
docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins/jenkins |
Here, we have mapped the Jenkins home directory /var/ jenkins_home in the container with the /jenkins directory located in our current directory. This means that if you are in the /Users/Khanh directory then you have mapped the /Users/Khanh/jenkins folder on your machine to the /var/ jenkins_home directory in the container. I also mapped port 8080 of the container with port 49001 on my machine.
If you are installing Jenkins using the Docker on Windows then you can run the following command:
1 |
docker run -p 49001:8080 -t jenkins/jenkins |
With the above statement, there will be no folders on your machine mapped to the Jenkins home directory in the container.
Result in my macOS as follows:
Then, if you have access to http://localhost:49001/, you will see the following output:
This is where we begin Jenkins installation.
This screen means that a password has been generated in the container’s /var/jenkins_home/secrets/initialAdminPassword file. You need to get that password to enter here. Since, I have mapped the /var/jenkins_home directory in the container with the /User/Khanh/jenkins directory, I just need to open the /User/Khanh/jenkins/secrets directory so I can get the password in the initialAdminPassword file to fill.
If you are running Docker on Windows then you can find in the console window that we are running to find this password.
When done, click Continue to continue.
This screen is used to select the plugins we want to install with Jenkins. There are two options:
- Suggest suggested plugins
- Select plugins to install.
You can choose as you wish. For the sake of simplicity, here I will select the Install suggested plugins. Below are the plugins that Jenkins will install:
After installing the plugins, Jenkins will ask us to install the admin account:
After filling in the information, click Save and Continue button:
This window allows you to configure the Root URL of Jenkins. You can change the default value according to your needs and then click Save and Finish!
Click Start using Jenkins button to start using Jenkins.
Home page: