Jenkins pushed the Docker image to a private warehouse

Since my Jenkins is docker installed in Qunhui NAS, I will take Jenkins installed by Docker as an example

Echo '= = = = = = = = = = = = = = = = Docker start = = = = = = = = = = = = = =' echo '= = = = = = = = = = = = = = = = log in ali cloud private images warehouse = = = = = = = = = = = = = ='#Defining the image name
IMAGE_NAME="scm"
#Viewing the Current Directory
pwd
#Go to the web directory where Dockerfil is located,scm-web is my project directory, and Dockerfile is in this directory
cd scm-web
#Viewing the Current DirectoryDocker login --username=${username} --password=${password} Registry.cn-hangzhou.aliyuncs.com echo "# tag" docker-t Registry.cn-hangzhou.aliyuncs.com/hopefun/w2002:$IMAGE_NAME-${BUILD_NUMBER} $WORKSPACE/SCM - web echo "# push to warehouse" docker Push registry.cn-hangzhou.aliyuncs.com/hopefun/w2002:$IMAGE_NAME-${BUILD_NUMBER} echo "# delete local mirror" docker rmi Registry.cn-hangzhou.aliyuncs.com/hopefun/w2002:$IMAGE_NAME-${BUILD_NUMBER} echo "# exit private warehouse" docker logout echo '= = = = = = = = = = = = = = = = Docker end = = = = = = = = = = = = = =' echo "deployment image = = = = = = = = = = = = = = = > > > > > > > > > > > > > > > > > > > > > > > registry.cn-hangzhou.aliyuncs.com/hopefun/w2002:$IMAGE_NAME-${BUILD_NUMBER}"Copy the code

Docker: Command not found Docker: Command not found

If a regular Docker mounts these two files to the Jenkins container, it can execute the Docker command.

/var/run/docker.sock
/bin/docker
Copy the code

This is a tutorial I read on the Internet, I haven’t tried it yet…

I’ll try it sometime, see if it works.


It can be the docker of my qunhui NAS. I first found the docker file under the shell command of NAS, and then copied the file to the homes directory.

#Cdnas docker file in /usr/localUnder the/bin /
cp /usr/local/bin/docker /volume1/homes/admin/jenkins_docker/bin
Copy the code

Then in the Web page of qunhui NAS to operate the Docker container, mount directory.

Then Jenkins sh build run shell script will report: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Docker can’t find the daemon, so we open port 2375 on the host. Docker -h TCP ://172.17.0.1:2375 version

Reference: blog.csdn.net/liumiaocn/a…

Then we add to the script:

Echo '= = = = = = = = = = = = = = = = Docker start = = = = = = = = = = = = = =' echo '= = = = = = = = = = = = = = = = log in ali cloud private images warehouse = = = = = = = = = = = = = ='#Defining the image name
IMAGE_NAME="scm"
#Viewing the Current Directory
pwd
#Go to the web directory where Dockerfil is located,scm-web is my project directory, and Dockerfile is in this directory
cd scm-web
#Viewing the Current DirectoryDocker login --username=${username} --password=${password} Registry.cn-hangzhou.aliyuncs.com echo "# tag" docker -h TCP ://172.17.0.1:2375 build-t Registry.cn-hangzhou.aliyuncs.com/hopefun/w2002:$IMAGE_NAME-${BUILD_NUMBER} $WORKSPACE/SCM - web echo "#" pushed to the warehouse docker - H TCP: / / 172.17.0.1:2375 push registry.cn-hangzhou.aliyuncs.com/hopefun/w2002:$IMAGE_NAME-${BUILD_NUMBER} echo "# delete local mirror" Docker -h TCP: / / 172.17.0.1:2375 rmi registry.cn-hangzhou.aliyuncs.com/hopefun/w2002:$IMAGE_NAME-${BUILD_NUMBER} echo "# Exit the private warehouse "docker logout echo '= = = = = = = = = = = = = = = = docker end = = = = = = = = = = = = = =' echo" deployment image = = = = = = = = = = = = = = = > > > > > > > > > > > > > > > > > > > > > > > registry.cn-hangzhou.aliyuncs.com/hopefun/w2002:$IMAGE_NAME-${BUILD_NUMBER}"Copy the code

So here we apply save in Jenkins.

Now build directly and look at the console output:

We are looking at the mirror warehouse of Ali Cloud container service

BingGo!!!!!!

After work ~ ~ ~ zhao xiao pang personal blog: https://zc.happyloves.cn:4443/wordpress/