SoFunction
Updated on 2025-03-10

Sample code for installing Jenkins using Docker

Two problems that are easy to encounter when installing containers in docker

is already allocated (the port is assigned)

Solution: Change the port

container to be able to reuse that name

Solution: View (delete) previous containers

docker ps -a | grep jenkins_im
docker rm jenkins_im

Start the docker service

sudo systemctl start docker

vi /home/jenkins/, create

version: '3'
services:
 jenkins: 
  container_name: 'jenkins'
  image: jenkins/jenkins:lts
  restart: always
  user: jenkins:994
  ports: 
  - "11005:8080"
  - "50000:50000"
  - "10051:10051"
  volumes:
  - /home/jenkins/data:/var/jenkins_home
  - /usr/bin/docker:/usr/bin/docker
  - /var/run/:/var/run/

If there is no such file before, it will not be saved after modification. Change vi to vim

Here are the installation steps

arrivegithub Copy command

docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts

Open the terminal and use ssh to connect to the remote test server

Paste the above command, modify the default port 8080, map it to other host ports, and specify the container name, press Enter, and if it goes well, a string of hash values ​​will be printed.

docker run --name jenkins_im -itd -p 11005:8080 -p 50000:50000 jenkins/jenkins:lts // -itd:Add interactive terminals,And let this commanddockerExecute in the background

Execute the following command to check whether the container is running

docker ps | grep jenkins_im

Execute the following command to print the information in the container. You will see an administrator's password. Save it. You will use it later. ctrl+c exit the log command.

docker logs -f jenkins_im

If the firewall is not closed, let the firewall release the 11005 port set above.

firewall-cmd --add-port=11005/tcp --permanent

Then reload the firewall

firewall-cmd --reload

At this time, you can access the IP and port number of the virtual machine in the browser scope. The next operation is:

  • Enter the administrator password you just saved
  • Select to install the recommended plug-in
  • If you see an offline reminder, it may be that the IP set up earlier cannot access Google's services. Some plug-ins need to access Google download and install. The solution is to set up an agent, or install offline. You can configure the Tsinghua Acceleration Source Download Plugin
  • Create an administrator account
  • There will be a URL in the instance configuration. This address needs to be used when connecting to gitlab in the future. If you need to modify it, you can modify it in the system settings.
  • After logging in, configure the url of the update site in advanced management plugins of the system. What url is it?Tsinghua open source mirror link
  • If you want to download the relevant plug-in on the official website, click the upload plug-in here to install it after downloading.
  • Run the container next time
docker start <container name>

This is the article about the sample code of using Docker to install Jenkins. For more related content on Docker installation of Jenkins, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!