gradle-docker-plugin: Docker file not found when using custom `dockerFile`
Expected Behavior
When setting a custom dockerFile for a DockerBuildImage task like here I’d expect the Docker file to be found.
Current Behavior
The Docker file is not found and I get
Error during callback
com.github.dockerjava.api.exception.InternalServerErrorException: {"message":"Cannot locate specified Dockerfile: /home/seschube/Development/HERE/oss/tools/review-toolkit/cli/Dockerfile-to-run-ORT"}
at com.github.dockerjava.jaxrs.filter.ResponseStatusExceptionFilter.filter(ResponseStatusExceptionFilter.java:52)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.client.ClientFilteringStages$ResponseFilterStage.apply(ClientFilteringStages.java:133)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.client.ClientFilteringStages$ResponseFilterStage.apply(ClientFilteringStages.java:121)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.process.internal.Stages.process(Stages.java:171)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:283)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.client.JerseyInvocation.lambda$invoke$1(JerseyInvocation.java:767)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.internal.Errors.process(Errors.java:316)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.internal.Errors.process(Errors.java:298)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.internal.Errors.process(Errors.java:229)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:414)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:765)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:456)
at com.bmuschko.gradle.docker.shaded.org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:357)
at com.github.dockerjava.jaxrs.async.POSTCallbackNotifier.response(POSTCallbackNotifier.java:29)
at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:50)
at com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier.call(AbstractCallbackNotifier.java:24)
Although:
$ ls /home/seschube/Development/HERE/oss/tools/review-toolkit/cli/Dockerfile-to-run-ORT
/home/seschube/Development/HERE/oss/tools/review-toolkit/cli/Dockerfile-to-run-ORT
Context
I’m trying to use a custom Docker file which has not the default name of “Dockerfile”.
Steps to Reproduce (for bugs)
$ git clone -b docker-debug https://github.com/heremaps/oss-review-toolkit.git $ ./gradlew cli:dockerBuildImage
Your Environment
Ubuntu 18.04, 64-bit
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21 (18 by maintainers)
Yes I agree. My test shows that when a Dockerfile sits in the inputDir, it will be taken. Also I can specify a dockerFile but the path specified is not absolute, it must be relative to the input dir specified. So lets say I set my inputDir to $projectDir and my dockerFile to “docker/Dockerfile” it works.
One other problem I found is that since it uses any Dockerfile that sits in the inputDir, if the Dockerfile changes, the up-to-date is not invalidated because the @input dockerFile was never specified therefore not part of the cache key.
Looking at the code again I think we should probably get rid of the property
inputDir. The base directory can always be derived of the parent directory of the Dockerfile aka the value of the propertydockerFile. I am not sure quite sure why there even is a differentiation between base directory and Dockerfile in Docker Java.My (brief) investigation so far indicates that the real issue is in fact in the underlying docker-java code (where this message comes from). Something is weird about the behavior when (not) setting
baseDirectory, probably somewhere around https://github.com/docker-java/docker-java/blob/de0c1d4b352b81c2f58aa4758eb9c431e4b05346/src/main/java/com/github/dockerjava/core/command/BuildImageCmdImpl.java#L333. But I didn’t yet have time to look deeper.I’m also slight confused by the naming. My understanding is that in docker-java’s code the “baseDirectory” is what the Docker CLI’s
buildcommand calls “context”. If a Dockerfile does not use anCOPYor related command, specifying the context is optional, and so should be specifying “baseDirectory”. However, it seems the code never allows “baseDirectory” to be unset, and will default to the parent directory of the Dockerfile, and maybe the problem is related to that.