Some methods to solve the problem of Jenkins integrating docker plug in
- 2021-11-10 11:16:54
The test environment uses Jenkins to integrate docker plug-in to realize the 1-key deployment service of the test environment. First, jenkins has installed docker build and publish plug-in, but there are 1 series of problems in operating job!
docker executes error reporting, Build step 'Docker Build and Publish' marked build as failure, which leads to many problems. More detailed error message: docker container does not support docker operation?
Analysis of the problem: jenkins is deployed using docker, so there will be no docker-related operation commands in the jenkins container, so the execution failed!
Solution: You need to map the host's docker environment to the jenkins container to use the docker command line
docker run --name myjenkins -p 8123:8080 -p 50000:50000 -v /run/docker.sock:/var/run/docker.sock -v /var/jenkins_home:/var/jenkins_home -u 0 -d jenkins/jenkins:lts
Execute again, the result is still wrong, and it has not been solved!
Prompt that there are no commands to execute in bin directory?
Analysis: We know that for any 1 environment installed, if you want to execute its command line in the linux environment, you need to add the environment variable:/usr/bin
Solution: Continue mapping host docker executable commands
docker run --name myjenkins -p 8123:8080 -p 50000:50000 -v /run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -v /var/jenkins_home:/var/jenkins_home -u 0 -d jenkins/jenkins:lts
tips: which command, somewhat similar to whereis lookup command or file: the former looks at the command in the system environment variable (returns the first result), the latter program name related path (returns all matching results)
Dependency not found: error while loading shared libraries: libltdl. so. 7: cannot open shared object file: No such ES90or/libltdl. so. 7
Analysis: Inside the jenkins container, because the container is not shared with the host, the library can be found on the host: cd usr/lib64/
Solution: Find the libltdl. so. 7 dependency library on the host machine and mount the container
docker run --name myjenkins -p 8123:8080 -p 50000:50000 -v /run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -v /usr/lib64/libltdl.so.7:/usr/lib/x86_64-linux-gnu/libltdl.so.7 -v /var/jenkins_home:/var/jenkins_home -v /var/data/shell:/var/data/shell -u 0 -d jenkins/jenkins:lts
no basic auth credentials is not certified
Analysis reason: This plug-in uses docker command inside jenkins container, build mirroring will not report error, is in the container, when push is needed to mirror warehouse, auth is needed
Solution: Directly add one line of authentication to job of jenkins, docker login-username=xxxx-password=xxxx nexus. xxxx. com
tips: After executing the command, one will be generated in the current directory. credentials records the account password information of logging in to nexus Mirror Warehouse
At this point, the previous steps have been completed, and the docker command can be used inside the jenkins container, so there is no need to jump out of the container to the host machine to execute build through the shh plug-in
push operation command, need to execute the start container script can!
docker containerization, everything mapped on the host and container is the same, that is, whether the host mounts the container's file or modifies the mounted host file in the container, it will be modified at the same time.