Encounter error when trying to build a docker image using jenkins/jnlp-agent-docker

Greeting! I setup a K8s-based Jenkins deployment using helm chart.

The installation of Jenkins controller in K8s cluster was smooth and I had no issue accessing the server once deployed.

I created a multi-branch project through Jenkins portal: not issue, either.

However, when I attempted to build project, which has following steps in its jenkinsfile:


stage(‘Build Docker Image’) {

sh “docker build --no-cache -t .azurecr.io/{pipelineParams.containerRegistryRepo}:{tag}-{branchTag} . --target=final --build-arg projectVersion={tag}-${branchTag}”

}

I got following error in the build log:

[Pipeline] sh

  • docker build --no-cache -t .azurecr.io/-ui:2024.06.25.2-controller . --target=final --build-arg projectVersion=2024.06.25.2-controller
    ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

The build was using the built-in kubernetes cloud.

Here is the log of launching the agent pod:


Waiting for next available executor
Agent default-mbgn3 is provisioned from template default

apiVersion: “v1”
kind: “Pod”
metadata:
annotations:
kubernetes.jenkins.io/last-refresh: “1719255279657”
labels:

kubernetes.jenkins.io/controller: “http___vtsjenkins_jenkins_svc_cluster_local_8080x”
name: “default-mbgn3”
namespace: “jenkins”
spec:
containers:

  • args:
    • “********”
    • “default-mbgn3”
      env:
    • name: “JENKINS_SECRET”
      value: “********”

      image: “jenkins/jnlp-agent-docker:latest”

Pleas note that the docker image of the build agent is jenkins/jnlp-agent-docker:latest.

According to my test, “ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?” seems to be caused by the fact that docker daemon is not running?

Any idea on the above error?

Thanks.