I'm setting up CI pipeline in Jenkins running in container. I'm using official jenkins/jenkins:latest docker image with no modifications. On Jenkins itself I installed docker plugins and added docker installation in global tool configuration as well as dockerTool in pipeline tools section.
I created container with following command:
docker run -d -u root -p 8080:8080 -p 50000:50000 -v /var/run/docker.sock:/var/run/docker.sock -v jenkins_home:/var/jenkins_home jenkins/jenkins:latest
I mounted docker.sock to use part of docker on host machine for building image. Here is part of Jenkinsfile, that is failing:
stage('PUSH') {
steps {
script {
dockerImage = docker.build 'mygithub/spring-petclinic:latest'
docker.withRegistry( '', 'dockerHubCreds' ) {
dockerImage.push()
}
}
}
}
The building of image is successful. The build fails only when I'm trying to push image to DockerHub. It says that there is no such file/dir called Docker, but previous step literally printed out docker build command.
I provided logs below.
docker build -t qeqoos/spring-petclinic:latest .
Sending build context to Docker daemon 63.25MB
Step 1/4 : FROM openjdk:8-jre-alpine3.9
---> f7a292bbb70c
Step 2/4 : COPY target/spring-petclinic-2.5.0-SNAPSHOT.jar /usr/bin/spring-petclinic.jar
---> ced11038c9dd
Step 3/4 : EXPOSE 80
---> Running in f222a20aad19
Removing intermediate container f222a20aad19
---> 3cd6a16e7890
Step 4/4 : ENTRYPOINT ["java", "-jar", "/usr/bin/spring-petclinic.jar", "--server.port=80"]
---> Running in 0a392d01e56b
Removing intermediate container 0a392d01e56b
---> 9afe8b544a7b
Successfully built 9afe8b544a7b
Successfully tagged qeqoos/spring-petclinic:latest
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withDockerRegistry
$ docker login -u qeqoos -p ******** https://index.docker.io/v1/
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.IOException: error=2, No such file or directory
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
Caused: java.io.IOException: Cannot run program "docker": error=2, No such file or directory
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
at hudson.Proc$LocalProc.<init>(Proc.java:252)
at hudson.Proc$LocalProc.<init>(Proc.java:221)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:995)
at hudson.Launcher$ProcStarter.start(Launcher.java:507)
at hudson.Launcher$ProcStarter.join(Launcher.java:518)
at org.jenkinsci.plugins.docker.commons.impl.RegistryKeyMaterialFactory.materialize(RegistryKeyMaterialFactory.java:101)
at org.jenkinsci.plugins.docker.workflow.AbstractEndpointStepExecution2.doStart(AbstractEndpointStepExecution2.java:53)
at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution.lambda$run$0(GeneralNonBlockingStepExecution.java:77)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Finished: FAILURE
Is there any better approach as for Jenkins in container, or any advice how to make Jenkins push image? Thank you.
CodePudding user response:
jenkins/jenkins:latest
default won't have docker client
binary, you just mount unix socket
to container, it's defintely not enough.
The command
in output I think just print out: what the docker command it plan to use, not means it already run it.
So, for you, you need to install docker client in jenkins
container:
- Either use bind mount:
docker run -v `which docker`:/usr/bin/docker ......
- Or, if the host's docker client not sutiable for container environment, directly download prebuilt
docker client
from here, copy thedocker
binary to container.