Recently, there was an online BUG in the team, which caused the wrong orders of several users. Because it was found in time, the customer service side corrected it before receiving complaints. So I wanted to bribe the test girl not to report the BUG this time, otherwise I would have to write a report, duplicate, etc. This thought a meal can be done, who knows the test sister does not eat, let me help her a favor…… .

This is… Before I could think about it, the test girl asked me to install A Jenkins on her computer using Docker. Last month, the testing department laid off some staff. Now the remaining staff of Python, Django and Jemeter have been rolled up. She installs Jenkins also for volume……

After helping to press, to prevent the back of the test department to find me, I wrote a tutorial to throw her. It’s actually pretty easy to install Jenkins with Docker. If you have CI/CD in your company, Jenkins is an essential component, hence the article you see today.

The preparatory work

It’s easy to get started. Install your Own Docker Desktop on your computer. If that doesn’t work out, you might want to rethink your career plans.

Download Jenkins Docker image

This can also be downloaded when you first start the Jenkins Docker container, but you can download it first so it doesn’t take too long to start up.

Start the Jenkins Docker

  • The first step is to create a new host directory on the computer to mount the Jenkins container
sudo mkdir -m 777 /var/jenkins_mount
Copy the code

The /var/jenkins_home directory of the Jenkins container will be mounted to the /var/jenkins_mount directory of the Jenkins container, so that the data in the Jenkins container can be persisted to the computer.

  • Start Jenkins Docker and execute the following command
docker run --name local_jenkins --rm -d -p 10240:8080 -p 10241:50000 -v /var/jenkins_mount:/var/jenkins_home jenkins/jenkins
Copy the code
  • Parameter interpretation
    • –name local_jenkins Set the container name to local_jenkins
    • — Rm deletes the container after the container is closed
    • -d runs in the background
    • -p 10240:8080 -p 10241:50000 Map port 10240 of the host to port 8080 of the Jenkins container, and map port 10241 of the host to port 50000 of the Jenkins container
    • -v /var/jenkins_mount:/var/jenkins_home Maps the /var/jenkins_home directory of the container to the /var/jenkins_mount directory of the host.

Initial setup

  • After starting, run the docker ps -l command to check whether a container named local_jeniks is running properly.
docker ps -l
CONTAINER ID   IMAGE             COMMAND                  CREATED          STATUS         PORTS                                               NAMES
48245973f208   jenkins/jenkins   "/ sbin/observatory - / usr /..."   11 seconds ago   Up 9 seconds   0.0. 0. 0:10240->8080/tcp, 0.0. 0. 0:10241->50000/tcp   local_jenkins
Copy the code
  • Set Jenkins’ mirror source

The host in the directory/var/jenkins_mount Hudson. Model. UpdateCenter. XML file contents modified into this (image source urls to the domestic)

<? xml version='1.1' encoding='UTF-8'? > <sites> <site> <id>default</id>
    <url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>
  </site>
</sites>
Copy the code
  • Browser access 127.0.0.1:10240 access Jenkins to initialize

This prompts you to use your initial password to unlock Jenkins Initial password in the/var/Jenkins container jenkins_home/secrets/initialAdminPassword, To the native/var/jenkins_mount/secrets/paste initialAdminPassword, enter here.

Here are some plugins for Jenkins to install during the initial login. I chose the default recommended plugins to install, and those in the know can choose their own plugins to install.

  • The final step is to create an administrator account so that you don’t need to log in with an initial password.

After the creation is completed, Jenkins initialization is completed, and you can experience it by yourself later. In the future, you can use Jenkins on the local machine and access it directly through http://127.0.0.1:10240/.

After the computer restarts, you need to re-execute the above docker run command to run the Docker.