Use Jenkins Docker Plugin in kubernetes cluster on GKE

2/15/2017

I followed this great tutorial to install Jenkins on my GKE kubernetes cluster, and start playing with CI. Everything went fine until I tried to use the docker plugin in my pipeline.

Here is a link to the issue I added to the github project I'm refering to:

https://github.com/GoogleCloudPlatform/continuous-deployment-on-kubernetes/issues/65

When I try to use the docker plugin like this:

stage "Prepare environment"
docker.image('node:4.1.2').inside {
    print "inside a node server"
    sh("echo test");  
    //sh("npm install");      
  }

I got the following error:

[Pipeline] stage (Prepare environment)
Using the ‘stage’ step without a block argument is deprecated
Entering stage Prepare environment
Proceeding
[Pipeline] sh
[play_PLR-437-jenkins-config-WQ5IB66PEGACJNE6UHFF54RVEEBWEEDWRSVCZM3YSVATI3UYUBXA] Running shell script
+ docker inspect -f . node:4.1.2
.
[Pipeline] withDockerContainer
$ docker run -t -d -u 0:0 -w /root/workspace/play_PLR-437-jenkins-config-WQ5IB66PEGACJNE6UHFF54RVEEBWEEDWRSVCZM3YSVATI3UYUBXA -v /root/workspace/play_PLR-437-jenkins-config-WQ5IB66PEGACJNE6UHFF54RVEEBWEEDWRSVCZM3YSVATI3UYUBXA:/root/workspace/play_PLR-437-jenkins-config-WQ5IB66PEGACJNE6UHFF54RVEEBWEEDWRSVCZM3YSVATI3UYUBXA:rw -v /root/workspace/play_PLR-437-jenkins-config-WQ5IB66PEGACJNE6UHFF54RVEEBWEEDWRSVCZM3YSVATI3UYUBXA@tmp:/root/workspace/play_PLR-437-jenkins-config-WQ5IB66PEGACJNE6UHFF54RVEEBWEEDWRSVCZM3YSVATI3UYUBXA@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat node:4.1.2
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.IOException: Failed to run image 'node:4.1.2'. Error: docker: Error response from daemon: mkdir /root/workspace: read-only file system.
    at org.jenkinsci.plugins.docker.workflow.client.DockerClient.run(DockerClient.java:125)
    at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:175)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:184)
    at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:126)
    at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:18)
    at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/var/jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:122)
    at org.jenkinsci.plugins.docker.workflow.Docker.node(jar:file:/var/jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:63)
    at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/var/jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:116)
    at WorkflowScript.run(WorkflowScript:12)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
    at sun.reflect.GeneratedMethodAccessor382.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
    at com.cloudbees.groovy.cps.Next.step(Next.java:58)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:163)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:328)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:80)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:240)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:228)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:63)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE

Basically this:

java.io.IOException: Failed to run image 'node:4.1.2'. Error: docker: Error response from daemon: mkdir /root/workspace: read-only file system.

More investigation in the link I specified above. Using docker in docker seems to be tricky in this situation. I'm new to jenkins but I guess it must be a way to make the docker plugin work in this context (GKE kubernetes cluster)

Thanks a lot in advance

Philippe

-- eussam
continuous-integration
google-kubernetes-engine
jenkins
jenkins-plugins
kubernetes

1 Answer

10/29/2018

I have stayed far away from docker "abstractions" through Jenkins plugins. You can simply execute shell commands directly to perform your docker workload(s) such as:

sh "docker build -t $SOME_NAME:$GIT_COMMIT_SHA ."
sh "docker run .."

or more specifically in your paste:

sh "docker run -d --name node node:4.1.2"
sh "docker exec -it node /bin/sh -c 'npm install'"
-- yomateo
Source: StackOverflow