Using image.inside() inside docker.withServer() does fails with the following error:
[Pipeline] withDockerContainer
$ docker run -t -d -u 1000:1000 -w "/var/jenkins_home/workspace/Utility Jobs/copy-schema" -v "/var/jenkins_home/workspace/Utility Jobs/copy-schema:/var/jenkins_home/workspace/Utility Jobs/copy-schema:rw" -v "/var/jenkins_home/workspace/Utility Jobs/copy-schema@tmp:/var/jenkins_home/workspace/Utility Jobs/copy-schema@tmp:rw" -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat dockerimage
[Pipeline] {
[Pipeline] sh
[copy-schema] Running shell script
sh: /var/jenkins_home/workspace/Utility Jobs/copy-schema@tmp/durable-f8d02fd0/pid: No such file or directory
sh: /var/jenkins_home/workspace/Utility Jobs/copy-schema@tmp/durable-f8d02fd0/jenkins-log.txt: No such file or directory
sh: /var/jenkins_home/workspace/Utility Jobs/copy-schema@tmp/durable-f8d02fd0/jenkins-result.txt: No such file or directory
[Pipeline] }
$ docker stop --time=1 d1f1d8173fcc89762825aeee7019aa24e88e4f9c87c08036083118cd4c708f26
$ docker rm -f d1f1d8173fcc89762825aeee7019aa24e88e4f9c87c08036083118cd4c708f26
[Pipeline]
I've debugged my Jenkins instance and it turns out that the docker inspect calls inside org.jenkinsci.plugins.docker.workflow.WithContainerStep.Execution.start() fail silently because the docker client can't connect to the docker host. The reason seems to be that the call to org.jenkinsci.plugins.docker.workflow.client.DockerClient.getVolumes(EnvVars, String) uses envHost which does not contain the environment variables set by withServer(). If I pass in all environment variables ( env) the call succeeds and the inside() step succeeds as well (the volume from the master is reused using --volumes-from).
I'm not sure about the other implications of passing in env instead of envHost.