Jenkins cannot use docker: Cannot connect to the Docker daemon

12/5/2019

I've installed jenkins in my k8s cluster through helm. Ive been trying to build the docker image and push it to gitlab registery so i can use it for deployment later though cloudbees docker plugin but i kept getting this error this error:

   Started by user admin
Running as SYSTEM
Building in workspace /var/jenkins_home/workspace/Build
using credential gitlab
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://gitlab.com/Ferios08/letsdevops-angular.git # timeout=10
Fetching upstream changes from https://gitlab.com/Ferios08/letsdevops-angular.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials gitlab
 > git fetch --tags --progress -- https://gitlab.com/Ferios08/letsdevops-angular.git +refs/heads/*:refs/remotes/origin/* # timeout=10
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision bbfedaeb976edde010c496c63de43ec01184011e (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f bbfedaeb976edde010c496c63de43ec01184011e # timeout=10
Commit message: "fixed deploy"
 > git rev-list --no-walk bbfedaeb976edde010c496c63de43ec01184011e # timeout=10
[Build] $ /var/jenkins_home/tools/org.jenkinsci.plugins.docker.commons.tools.DockerTool/docker/bin/docker build -t registry.gitlab.com/ferios08/letsdevops-angular --pull=true /var/jenkins_home/workspace/Build
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Build step 'Docker Build and Publish' marked build as failure
Finished: FAILURE

any ideas how to fix it? and thanks

-- Firas Chbiki
cloudbees
docker
jenkins
kubernetes
kubernetes-helm

2 Answers

12/9/2019

You are trying to connect to docker daemon inside the container, but docker daemon inside your container is not running.

There are several possibilities:

  1. You can run docker in docker

  2. You can bind the docker socket of your cluster to your container with -v

docker run -v /var/run/docker.sock:/var/run/docker.sock

  1. You can connect docker inside your container to some remote docker socket using docker context (with docker version >=19.03)

  2. You can just install jenkins outside of the cluster

-- Dennis Meissel
Source: StackOverflow

12/6/2019

Seems to me your docker daemon is not running.

-- ATv
Source: StackOverflow