Search code examples
dockerkubernetesjenkinsgroovycontainers

Jenkins using Kubernetes plugin - Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?


Using Jenkins on Kubernetes plugin and using Jenkins as a code.

I'm getting this error when trying to use 'docker build'

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

  1. I tried to mount /var/run/docker.sock.. but still not working..
  2. I tried to use runAsUser: root to run with root permissions... but still not working..

My Jenkins as a code pod template configuration -

  Jenkins:config:
    chart: jenkins
    namespace: default
    repo: https://charts.jenkins.io
    values:
      agent:
        enabled: true
        podTemplates:
          jenkins-slave-pod: |
            - name: jenkins-xxx-pod
              label: ecs-slave
              serviceAccount: jenkins-xxx-prod
              containers:
                - name: main
                  image: '805xxxx.dkr.ecr.us-west-2.amazonaws.com/slave:ecs-xxxx-node_master-3'
                  command: "sleep"
                  args: "30d"
                  privileged: true
                  runAsUser: root
              volumes:
                - hostPathVolume:
                    hostPath: "/var/run/docker.sock"
                    mountPath: "/var/run/docker.sock"

Solution

  • I assume that you are using k8s >= v1.24 where docker as runtime is not supported anymore.

    I would also add that mounting docker socket is not a good practice from security perspective.

    If you want to build container image in k8s please use podman or kaniko.