Issue with Jenkins on Kubernetes when building docker containers

4/18/2020

I have setup jenkins to run on GKE kubernetes cluster. I wrote the Jenkinsfile to define CI/CD pipeline. But when it reaches the docker build command, it gives me the following error: "Segmentation fault (core dumped) Build step 'Execute shell' marked build as failure Finished: FAILURE"

After that I setup a new test job and run random command and it executes successfully but when I run docker version, I get the same error. The error comes when I run docker commands. I have restarted my jenkins pod, freshly setup a new jenkins instance on the cluster but the error was still there. I need help!! Any feedback is much appreciated.

Regards,

-- devops_enthusiast
containers
docker
google-kubernetes-engine
jenkins
kubernetes

1 Answer

4/18/2020

The reason you are having an issue is because you are trying to run docker inside a container. The Jenkins pod(s) are themselves running in a container (docker or otherwise) inside the kubernetes cluster. It can be very tricky to run docker inside a container. There is a lot of help out there on how to do it - search for "docker in docker" or "dind", but there are a lot of reasons you do not want to do that. Security being a big issue here.

Instead, you may consider some other way to build your container images, without using a docker command. Search for "building containers without docker" or something similar. My favourite is to use kaniko. Kaniko avoids the issues of running docker inside a container, and is compatible with the same Dockerfile you already use.

There are other ways to do this as well. Searching will give some good results.

-- dlaidlaw
Source: StackOverflow