Build assembly line from scratch (I)
Install Docker
1. Remove old Docker
yum remove docker*
Copy the code
2. Set the Docker yum source
2.1 Install yum Utils
yum install -y yum-utils
Copy the code
2.2 Setting the Yum source of Docker Aliyun
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Copy the code
3. Install the docker
3.1 Select the appropriate Docker version
yum list docker-ce --showduplicates | sort -r
Copy the code
- By default, the latest version of Docker will be installed. Generally, we will choose a relatively stable version in the process of use. The latest version carries some risks.
- We can choose one of the above versions to install
3.2 installation docker
Yum install docker-ce-3:19.03.9-3.el7.x86_64 containerd.io Docker-ce-cli-3:19.03.9-3.el7.x86_64 containerd.ioCopy the code
- Enter y for confirmation twice during installation
- Finally, complete appears, and the Docker installation is complete
2. Install Jenkins
Please refer to Jenkins’ official documents in Chinese.
The official documentation on Jenkins is very detailed and complete.
Here are the steps to follow Jenkins
1. Select the Docker image
Docker Hub selects image
- Registry.hub.docker.com/
- There is no Docker account, you can register one via email
Search Jenkins
When you click on it, the official says the image has been abandoned for two years and offers a new address.
Click on tags to select a different image.
2Jenkins install official commands
docker run \
-u root \
--rm \
-d \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins-data:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkinsci/blueocean
Copy the code
— rm
(Optional) The Docker container is automatically deleted when Jenkinsci/BlueOcean is closed. If you need to quit Jenkins, this can be kept tidy.
-d
(Optional) JenkinSCI/BlueOcean runs the container in the background (that is, “detached” mode) and outputs the container ID. If you do not specify this option, a running Docker log for this container is printed in the terminal window.
-p 8080:8080
Map (for example, Publish) port 8080 on the Jenkinsci/BlueOcean container to port 8080 on the host. The first number represents the port on the host, and the last represents the port on the container. Therefore, if you specify -p 499:8080 for this option, you will access Jenkins on the host through port 49000.
-p 50000:50000
(Optional) Map port 50000 on the Jenkinsci/BlueOcean container to port 50000 on the host. This is required if you have one or more jnlp-based Jenkins agents set up on other machines that interact with the jenkinsci/blueocean container (acting as the “master” Jenkins server, or simply “Jenkins master”). By default, the JNLP-based Jenkins agent communicates with the Jenkins master over TCP port 50000. You can change the port number on Jenkins’ primary server on the Configure Global Security page. If you want to change the TCP port value of the JNLP proxy port on your Jenkins host to 51000 (for example) then you need to re-run Jenkins (via this Docker run… Command) and specify the “publish” option -p 52000:51000, where the last value matches the change value on Jenkins Master, the first value is the port number on the Jenkins host, through which, Jnlp-based Jenkins agent communicates with Jenkins host – for example 52000.
-v jenkins-data:/var/jenkins_home \
(Optional, but strongly recommended) Map the /var/jenkins_home directory in the container to the volume with the name jenkins-data. If the volume does not exist, the Docker run command will automatically create the volume for you. If you wish to restart Jenkins every time (via this Docker Run… Command) to keep Jenkins state, this option is required. If you do not specify this option, Jenkins will effectively reset to a new instance after each reboot. Note: The jenkins-data volume can also be created with the docker volume create command: Docker volume create Jenkins-data instead of mapping /var/jenkins_home to a docker volume, you can also map this directory to a directory on your computer’s local file system. For example, to specify the options – v $HOME/Jenkins: / var/jenkins_home will container/var/Jenkins jenkins_home directory is mapped to a local computer the directory subdirectories, The $HOME directory is usually /Users/
/ Jenkins or/HOME /
/ Jenkins.
-v jenkins-data:/var/jenkins_home
(Optional, but strongly recommended) Map the /var/jenkins_home directory in the container to the volume with the name jenkins-data. If the volume does not exist, the Docker run command will automatically create the volume for you. If you wish to restart Jenkins every time (via this Docker Run… Command) to keep Jenkins state, this option is required. If you do not specify this option, Jenkins will effectively reset to a new instance after each reboot.
Note: The jenkins-data volume can also be created with the docker volume create command: Docker volume create Jenkins-data instead of mapping /var/jenkins_home to a docker volume, you can also map this directory to a directory on your computer’s local file system. For example, to specify the options – v $HOME/Jenkins: / var/jenkins_home will container/var/Jenkins jenkins_home directory is mapped to a local computer the directory subdirectories, The $HOME directory is usually /Users/
/ Jenkins or/HOME /
/ Jenkins
-v /var/run/docker.sock:/var/run/docker.sock
(Optional /var/run/docker.sock indicates the UNIX-based socket through which the Docker daemon listens. This mapping allows the Jenkinsci/BlueOcean container to communicate with the Docker daemon, which is required if the Jenkinsci/BlueOcean container needs to instantiate other Docker containers. If a declarative pipe is run, its syntax includes the Agent part using Docker
- This is from Jenkins’ website
3. Start the docker
systemctl start docker
Copy the code
4. Configure Aliyun Docker image acceleration
1. Log in to Aliyun
2. Select the container mirroring service
3. Select Mirror Acceleration
4. Copy the data to your own machine based on your system selection
4. Install Jenkins
-
Run the following command to install
docker run \ -u root \ -d \ -p 8080:8080 \ -p 50000:50000 \ -v jenkins-data:/var/jenkins_home \ -v /etc/localtime:/etc/localtime:ro \ -v /var/run/docker.sock:/var/run/docker.sock \ --restart=always \ jenkinsci/blueocean Copy the code
- Once the download is complete, see if Jenkins successfully launches
- Jenkins can now be accessed via IP :8080
- At this time, you need to enter the password. Docker was mounted during startup, so the location of the secondary directory will also change
- You can obtain this password by viewing the boot log
4.1 Viewing the Docker ID
docker ps
Copy the code
4.2 Viewing Logs By ID
docker logs 95db67934576
Copy the code
- That’s the password in the red box. Copy it into Jenkins
5. Follow the Jenkins plugin
- It is well known that Jenkins has a large number of powerful plug-ins.
- Select recommended Installation
6. Create an administrator
- Next click Reboot.
- Refresh the page to go to the login page
- At this point, Jenkins is set up,