Docker: not found in Jenkins pipeline

This blog, which I wrote, has plenty of info on the problems with running Jenkins pipelines with Docker.

I recently founded a company called Nestybox that has created a container runtime (aka runc) that enables Docker to deploy containers that act like virtual hosts and can run system-level software such as Docker in them, without using privileged containers. It solves many of the issues described by Jerome in his docker-in-docker blog post (see Jerome’s comment above).

We have a solution that runs Jenkins + Docker inside the system container, avoids many of the problems listed in this thread, and does so in complete isolation from the Docker on the host. Check it out, hopefully it will help!

2 Likes

Awesome stuff! This worked perfectly for me! I simply spun up a ubuntu 19.04 VM, and followed the Sysbox Installation Guide and @ctalledo’s blog post and was able to get Docker working in Jenkins pipelines (running in a dockerized Jenkins installation). More details here.

I meet same issue, it fixed mine. Thanks.

this worked for me too.

docker run -u 0 --privileged --name jenkins -it -d -p 8080:8080 -p 50000:50000 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/usr/bin/docker \
-v /home/jenkins_home:/var/jenkins_home \
jenkins/jenkins:latest
1 Like

Although using “–privileged” flag while starting docker container docker run -u 0 --privileged --name jenkins ... may allow enabling docker in Jenkins pipeline, there are certain implications of starting docker in privileged mode

tanx more need this work for me …
خرید گیفت کارت

This solution worked for me. Thank you!

docker run -u 0 --privileged --name jenkins -d -p 8080:8080 -p 50000:50000 -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts

worked for me.

docker run -d -u root -v /var/jenkins_home:/var/jenkins_home -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -p 8081:8080 -p 5001:5000 --name jenkins-docker --privileged jenkins/jenkins:lts

none of these are working for me :confused:
I’ve tried -u root and --group-add 0, --privileged too. $(which docker) is not working inside the docker command buts works separately so I’ve replaced $(which docker) with the $(which docker) literal which is something like C:/Program Files/..../bin/docker.
I’ve also tried docker on docker but not working.
I’d be happy if I’ve got a separate error. But Jenkins is giving me

/usr/bin/docker: 5: /usr/bin/docker: Cannot fork

because it cannot identify docker after all this. help :frowning:

but how to resolve this at host level,as my jenkins pod running in kubernetes and facing the same issue,if any body can help me with the deployment.yaml file

apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-app
labels:
 app: jenkins-app
spec:
replicas: 1
selector:
 matchLabels:
   app: jenkins-app
template:
 metadata:
   labels:
     app: jenkins-app
 spec:
   securityContext:
     runAsUser: 1000
     runAsGroup: 3000
     fsGroup: 1234
   containers:
   - name: jenkins-app
     image: jenkins/jenkins:latest
     imagePullPolicy: Always
     ports:
     - name: http-port
       containerPort: 8080
     - name: jnlp-port
       containerPort: 50000
     volumeMounts:
       - name: jenkins-home
         mountPath: /var
         subPath: jenkins_home
       - name: docker-sock
         mountPath: /var/run/docker.sock
     securityContext:
         allowPrivilegeEscalation: false
   volumes:
   - name: jenkins-home
     persistentVolumeClaim:
       claimName: jenkins-pv-claim
   - name: docker-sock
     hostPath:
       path: /var/run/docker.sock
   dnsPolicy: ClusterFirst
---
apiVersion: v1
kind: Service
metadata:
name: jenkins-app-service
labels:
 app: jenkins-app-service
spec:
selector:
 app: jenkins-app
type: LoadBalancer  
ports:
- port: 8080
 protocol: TCP
 targetPort: 8080
 nodePort: 30003
---
apiVersion: v1
kind: Service
metadata:
name: jenkins-jnlp-service
labels:
 app: jenkins-jnlp-service
spec:
selector:
 app: jenkins-app
type: ClusterIP  
ports:
- port: 50000
 protocol: TCP
 targetPort: 50000  
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-pv-volume
annotations:
 pv.beta.kubernetes.io/gid: "1234"
labels:
 type: local
spec:
storageClassName: manual
capacity:
 storage: 6Gi
accessModes:
 - ReadWriteOnce
hostPath:
 path: "/var/jenkins_home"

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-pv-claim
spec:
storageClassName: manual
accessModes:
 - ReadWriteOnce
resources:
 requests:
   storage: 3Gi


it works for me, thank you so much

This is the answer in case you struggle with the same issue.
docker run
-u root
–rm
-d
-p 8080:8080
-p 50000:50000
–name myjenkin
-v $(which docker):/usr/bin/docker
-v jenkins-data:/var/jenkins_home
-v /var/run/docker.sock:/var/run/docker.sock
jenkins/jenkins

Hmm, this results in “missing GLIBC” error in Jenkins.

sh “ssh -o StrictHostKeyChecking=no ubuntu@172.31.2.57 docker run -d -p 8080:8080 --name cloudcandy SXSSXX/javawebapp:${buildNumber}”

I have error in comand not found