Cannot connect to the Docker daem

After jenkins is delivered to the k8s cluster, when jenkins first builds the dubbo provider, an error is reported:

+ docker build -t .
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

After repeated construction, the following errors will be reported, roughly similar to the above errors:

+ docker build -t .
time="2020-05-03T10:51:12+08:00" level=error msg="failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial unix /var/run/docker.sock: connect: connection refused"
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

The answer on Baidu is to restart docker.

Because jenkins pod is running on, I have restarted the docker of this node; because docker push may use, I have also restarted But it doesn't work.


After Wang dao k8s's Q & a group sent out the questions, some students gave suggestions to re build jenkins image once.

Check the Dockerfile file:

Because another Dockerfile is used for jenkins 2.176.2.

[root@hdss7-200 jenkins]# pwd
[root@hdss7-200 jenkins]# ll -trh
total 944M
-rw-r--r-- 1 root root 944M Nov 18 18:19 jenkins-v2.176.2-with-docker.tar
-rw------- 1 root root  151 Apr 21 13:52 config.json
-rw------- 1 root root 1.7K Apr 21 13:54 id_rsa
-rwxr-xr-x 1 root root  14K Apr 21 14:00
-rw-r--r-- 1 root root  350 Apr 29 10:03 Dockerfile
-rw-r--r-- 1 root root  317 Apr 29 10:05 Dockerfile.ori.176
[root@hdss7-200 jenkins]# cat Dockerfile
USER root
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\ 
    echo 'Asia/Shanghai' >/etc/timezone
ADD id_rsa /root/.ssh/id_rsa
ADD config.json /root/.docker/config.json
RUN echo "    StrictHostKeyChecking no" >> /etc/ssh/ssh_config &&\

build image:

[root@hdss7-200 jenkins]# docker build . -t
Sending build context to Docker daemon  989.4MB
Step 1/7 : FROM
 ---> 22b8b9a84dbe
Step 2/7 : USER root
 ---> Using cache
 ---> f6345f239a6e
Step 3/7 : RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&    echo 'Asia/Shanghai' >/etc/timezone
 ---> Using cache
 ---> 9f3ee3ebf906
Step 4/7 : ADD id_rsa /root/.ssh/id_rsa
 ---> Using cache
 ---> 1274c52edb35
Step 5/7 : ADD config.json /root/.docker/config.json
 ---> Using cache
 ---> 69062560cff7
Step 6/7 : ADD /
 ---> Using cache
 ---> bf20ac214571
Step 7/7 : RUN echo "    StrictHostKeyChecking no" >> /etc/ssh/ssh_config &&    /
 ---> Using cache
 ---> 999989cba3be
Successfully built 999989cba3be
Successfully tagged

Push jenkins image to harbor warehouse:

[root@hdss7-200 jenkins]# docker push
The push refers to repository []
6e27d031df7b: Layer already exists 
004f4ad25d03: Layer already exists 
45774a545354: Layer already exists 
fa272cd168be: Layer already exists 
8542480a9979: Layer already exists 
e0485b038afa: Layer already exists 
2950fdd45d03: Layer already exists 
cfc53f61da25: Layer already exists 
29c489ae7aae: Layer already exists 
473b7de94ea9: Layer already exists 
6ce697717948: Layer already exists 
0fb3a3c5199f: Layer already exists 
23257f20fce5: Layer already exists 
b48320151ebb: Layer already exists 
911119b5424d: Layer already exists 
5051dc7ca502: Layer already exists 
a8902d6047fe: Layer already exists 
99557920a7c5: Layer already exists 
7e3c900343d0: Layer already exists 
b8f8aeff56a8: Layer already exists 
687890749166: Layer already exists 
2f77733e9824: Layer already exists 
97041f29baff: Layer already exists 
v2.190.3.20200503: digest: sha256:a95ec23858fc06813b71ff6a874cc9e97729c4f61bca62a2086b75d8b596f3ed size: 5130

Modify the resource allocation list:

[root@hdss7-200 jenkins]# cd /data/k8s-yaml/jenkins/
[root@hdss7-200 jenkins]# cat dp.yaml
kind: Deployment
apiVersion: extensions/v1beta1
  name: jenkins
  namespace: infra
    name: jenkins
  replicas: 1
      name: jenkins
        app: jenkins 
        name: jenkins
      - name: data
          server: hdss7-200
          path: /data/nfs-volume/jenkins_home
      - name: docker
          path: /run/docker.sock
          type: ''
      - name: jenkins
        imagePullPolicy: IfNotPresent
        - containerPort: 8080
          protocol: TCP
        - name: JAVA_OPTS
          value: -Xmx512m -Xms512m
        - name: data
          mountPath: /var/jenkins_home
        - name: docker
          mountPath: /run/docker.sock
      - name: harbor
        runAsUser: 0
    type: RollingUpdate
      maxUnavailable: 1
      maxSurge: 1
  revisionHistoryLimit: 7
  progressDeadlineSeconds: 600

Application resource configuration list of any k8s cluster node:

[root@hdss7-21 ~]# kubectl apply -f
deployment.extensions/jenkins configured

The jenkins pod of dashboard has been started: jenkins previously ran on, and now it is scheduled to

Even though the jenkins pod in k8s has been started, it will take a while for the web interface on the browser to resume opening.

After rebuild:

What went wrong has passed:

Build successful:

Students help me analyze the reasons:

Because the socket file of the original image is faulty, it needs to be rebuilt.

Thanks for the old boy's k8s container cloud course.

Tags: Linux jenkins Docker JSON ssh

Posted on Mon, 04 May 2020 17:40:42 -0400 by mr_tron