Hello,
I’m using Jenkins 2.466.
I’m trying to use Docker inside Pipeline with below code.
pipeline {
agent any
stages {
stage ('build') {
when {
anyOf {
branch 'preprod'
}
}
agent {
docker {
image 'maven:3.9.8-eclipse-temurin-8'
// caching data on the agent between Pipeline runs.
args '-v $HOME/.m2:/root/.m2'
// Run the container on the node specified at the
// top-level of the Pipeline, in the same workspace,
// rather than on a new node entirely:
reuseNode true
}
}
steps {
sh 'mvn clean package'
}
}
}
}
Jenkins setup:
In my company, Jenkins has not been set up as per the documentation, like, running a docker:dind image and referring that in the Jenkins’ container’s Envrionment variable.
--env DOCKER_HOST=tcp://docker:2376
.
Instead, the Host Docker’s Unix socket is exposed. Like,
docker run -d --restart=always \
-p 127.0.0.1:2376:2375 \
-v /var/run/docker.sock:/var/run/docker.sock \
alpine/socat \
tcp-listen:2375,fork,reuseaddr unix-connect:/var/run/docker.sock
So, I tried to do the same setup in my local machine to do R&D and when running the Jenkins container, the only difference is, I added DOCKER_HOST environment variable --env DOCKER_HOST=tcp://172.17.0.2:2375
, where, “172.17.0.2” is the IP address of the “alpine/socat” container.
So final run command is,
docker run \
--name jenkins-blueocean-2 \
--restart=on-failure \
--detach \
--env DOCKER_HOST=tcp://172.17.0.2:2375 \
--env DOCKER_CERT_PATH=/certs/client \
--env DOCKER_TLS_VERIFY=1 \
--publish 8088:8080 \
--volume jenkins-data-2:/var/jenkins_home \
--volume jenkins-docker-certs:/certs/client:ro \
myjenkins-blueocean
This setup is only working fine when using “Docker Agent Templates” (Manage Jenkins → Clouds → New Cloud).and referring to those templates inside “label” in the pipeline.
But when I try to make use of Pipeline’s integrated Docker feature, with the above Pipeline code, I’m getting above mentioned error.
Please let me know how do I get this to working.
Thank you.