Dockerfile-maven: Error building image

Created on 14 Jun 2017  路  14Comments  路  Source: spotify/dockerfile-maven

Environemnt
Docker for Mac, v 17.0.3.1
Maven, v 3.5.0
Java, v 1.8.0_131

pom.xml,

<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
  <execution>
     <id>default</id>
                        <goals>
                            <goal>build</goal>
                            <goal>push</goal>
                        </goals>
                    </execution>
                </executions>
<configuration>
                    <contextDirectory>${project.basedir}</contextDirectory>
                    <writeTestMetadata>false</writeTestMetadata>
                    <dockerInfoDirectory>${project.basedir}</dockerInfoDirectory>
                    <verbose>true</verbose>
                    <forceCreation>true</forceCreation>
                    <repository>xxxxxxx/${project.name}</repository>
                    <tag>${project.version}</tag>
                    <pullNewerImage>false</pullNewerImage>
</configuration>

Building the image from the console using,

docker -D build -t xxxxx:1.x.x-SNAPSHOT . --> OK

mvn -X dockerfile:build --> ERROR

com.spotify.docker.client.exceptions.DockerRequestException: Request error: POST unix://localhost:80/build?t=xxx%3A1.x.x-SNAPSHOT: 500, body: {"message":"Cannot locate specified Dockerfile: Dockerfile"}

    at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:2387)
    at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:2337)
    at com.spotify.docker.client.DefaultDockerClient.build(DefaultDockerClient.java:1376)
    at com.spotify.docker.client.DefaultDockerClient.build(DefaultDockerClient.java:1348)
    at com.spotify.plugin.dockerfile.BuildMojo.buildImage(BuildMojo.java:157)
    ... 25 more

i think it is the same issue as this one,
https://github.com/spotify/docker-client/issues/479
but setting the $DOCKER_HOST environment variable to unix:///var/run/docker.sock does not fix the problem,

ran the following command,

curl -v --unix-socket /var/run/docker.sock http:/_ping
* Unwillingly accepted illegal URL using 1 slash!
* Rebuilt URL to: http://_ping/
*   Trying /var/run/docker.sock...
* Connected to _ping (/Users/xxxxxx/Library/Containers/com.doc) port 80 (#0)
> GET / HTTP/1.1
> Host: _ping
> User-Agent: curl/7.51.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Content-Length: 29
< Content-Type: application/json
< Date: Wed, 14 Jun 2017 05:15:21 GMT
< 
{"message":"page not found"}
* Curl_http_done: called premature == 0
* Connection #0 to host _ping left intact

but ran this other one
curl --unix-socket /var/run/docker.sock "http:/v1.24/_ping" --> OK
Any idea on how to fix the issue?

Most helpful comment

@mashurex in that repo your .dockerignore file contains ** which is being interpreted as:

The ** characters matches zero or more characters crossing directory boundaries.

and thus the Dockerfile in the project root is not sent in the Docker context. If you remove that line from the .dockerignore then the image is built fine for me.

Are you expecting the ** entry to mean something else?

@osvacaneljr @ganeshm25 what does your .dockerignore file look like?

All 14 comments

does ${project.basedir} contain a file named Dockerfile?

Yes there is a Dockerfile sitting in ${project.basedir} , this is the reason why building the image using docker works ok.

I'm seeing the same thing as well:

Environment

OS: MacOS Sierra 10.12.5
Docker: 17.03.1-ce, build c6d412e
Java: Oracle JDK 1.8.0_112-b16 x86_64
Maven: 3.3.9

Maven config

```xml

com.spotify
dockerfile-maven-plugin
${dockerfile-maven.version}

cordiance-config-admin
${project.version}
${project.basedir}
true
false
${project.basedir}



default
package

build



## Test Output
```shell
$ curl -v --unix-socket /var/run/docker.sock "http:/v1.24/_ping"
* Unwillingly accepted illegal URL using 1 slash!
*   Trying /var/run/docker.sock...
* Connected to v1.24 (/Users/mustafa/Library/Containers/com.docker.) port 80 (#0)
> GET /_ping HTTP/1.1
> Host: v1.24
> User-Agent: curl/7.51.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Api-Version: 1.27
< Content-Length: 2
< Content-Type: text/plain; charset=utf-8
< Date: Mon, 19 Jun 2017 16:16:23 GMT
< Docker-Experimental: true
< Server: Docker/17.03.1-ce (linux)
< 
* Curl_http_done: called premature == 0
* Connection #0 to host v1.24 left intact
OK

$ curl -v --unix-socket /var/run/docker.sock http:/_ping
* Unwillingly accepted illegal URL using 1 slash!
* Rebuilt URL to: http://_ping/
*   Trying /var/run/docker.sock...
* Connected to _ping (/Users/mustafa/Library/Containers/com.docker.) port 80 (#0)
> GET / HTTP/1.1
> Host: _ping
> User-Agent: curl/7.51.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Content-Length: 29
< Content-Type: application/json
< Date: Mon, 19 Jun 2017 16:17:20 GMT
< 
{"message":"page not found"}
* Curl_http_done: called premature == 0
* Connection #0 to host _ping left intact

Is there any current workaround to this issue ? or any rollback version that doesnt run to this issue?

Is it possible to create a minimal repo that would reproduce this error? It is not really clear what the cause is - the docker daemon error message seems to indicate there is no Dockerfile in the context directory.

I created a sample repo at https://github.com/mashurex/dockerfile-maven-issue-repro that reproduces the issues I'm seeing.

@mashurex in that repo your .dockerignore file contains ** which is being interpreted as:

The ** characters matches zero or more characters crossing directory boundaries.

and thus the Dockerfile in the project root is not sent in the Docker context. If you remove that line from the .dockerignore then the image is built fine for me.

Are you expecting the ** entry to mean something else?

@osvacaneljr @ganeshm25 what does your .dockerignore file look like?

The ** entry was an artifact as I was trying to quickly make a sample repo. However, if you run docker build ... it still builds the image exactly as you'd expect. It's being told to ignore everything except for the target/application.jar file.

EDIT: I didn't read your previous comment close enough.
Removing the ** definitely worked. If I had !Dockerfile and keep the ** it works as well.

Right, it seems like docker build interprets a ** to mean something else than docker-client is currently interpreting it to mean. An issue should probably be filed in that project to fix that.

But, do you need ** in your .dockerignore?

Just to be clear, I am not able to reproduce the error if I remove the .dockerignore file. Nor can I reproduce it if I remove or comment out ** from the .dockerignore file in the repo you created. I can however reproduce the problem if the .dockerignore file contains:

**
!target/application.jar

Building fine with no .dockerignore:

[mattbrown@mattbrown-air dockerfile-maven-issue-repro]$ docker rmi ashurex/hello-world
Untagged: ashurex/hello-world:latest
Deleted: sha256:911dc7c36388c325564f6119c155529ce65c6a15a886139fdfe535999721b725
Deleted: sha256:2c6fdeba15ad8dec1b1339ab6f7cc994fb27d915f7fd959abb198daf9f51fc38
Deleted: sha256:8e0951d80f186fe69995c6fa518155c6fa35293ab30365b6cbcb3cc683265055

[mattbrown@mattbrown-air dockerfile-maven-issue-repro]$ /bin/rm .dockerignore

[mattbrown@mattbrown-air dockerfile-maven-issue-repro]$ mvn -Pdocker clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-spotify-docker-repro 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-spotify-docker-repro ---
[INFO] Deleting /private/tmp/dockerfile-maven-issue-repro/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-spotify-docker-repro ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /private/tmp/dockerfile-maven-issue-repro/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-spotify-docker-repro ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /private/tmp/dockerfile-maven-issue-repro/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-spotify-docker-repro ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /private/tmp/dockerfile-maven-issue-repro/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-spotify-docker-repro ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-spotify-docker-repro ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ maven-spotify-docker-repro ---
[INFO] Building jar: /private/tmp/dockerfile-maven-issue-repro/target/application.jar
[INFO]
[INFO] --- dockerfile-maven-plugin:1.3.0:build (default) @ maven-spotify-docker-repro ---
[INFO] Using Google application default credentials
[INFO] loaded credentials for user account with clientId=xxx
[INFO] Building Docker context /private/tmp/dockerfile-maven-issue-repro
[INFO]
[INFO] Image will be built as ashurex/hello-world:latest
[INFO]
[INFO] Step 1/4 : FROM openjdk:8-jdk-alpine
[INFO] Pulling from library/openjdk
[INFO] Digest: sha256:96d8e4f8b93cbdeca2ffa147b72505f11c6272cda9627e7f544c38d77a1bfd4e
[INFO] Status: Image is up to date for openjdk:8-jdk-alpine
[INFO]  ---> e7d97a0b8e2c
[INFO] Step 2/4 : ENTRYPOINT sh -c java -jar /application.jar
[INFO]  ---> Using cache
[INFO]  ---> 50e3dab91445
[INFO] Step 3/4 : ADD target/application.jar /application.jar
[INFO]  ---> 97a161f4c9ab
[INFO] Removing intermediate container a0012b5e480f
[INFO] Step 4/4 : RUN sh -c "touch /application.jar"
[INFO]  ---> Running in ebb8b9e7b50d
[INFO]  ---> 04624e2a5c73
[INFO] Removing intermediate container ebb8b9e7b50d
[INFO] Successfully built 04624e2a5c73
[INFO]
[INFO] Detected build of image with id 04624e2a5c73
[INFO] Building jar: /private/tmp/dockerfile-maven-issue-repro/target/application-docker-info.jar
[INFO] Successfully built ashurex/hello-world:latest
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.747 s
[INFO] Finished at: 2017-06-23T09:45:12-04:00
[INFO] Final Memory: 33M/331M
[INFO] ------------------------------------------------------------------------

With the original .dockerignore:

[mattbrown@mattbrown-air dockerfile-maven-issue-repro]$ git reset --hard
HEAD is now at c2089b8 Removed $@ copy/paste issue

[mattbrown@mattbrown-air dockerfile-maven-issue-repro]$ cat .dockerignore
**
!target/application.jar

[mattbrown@mattbrown-air dockerfile-maven-issue-repro]$ mvn -Pdocker clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-spotify-docker-repro 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-spotify-docker-repro ---
[INFO] Deleting /private/tmp/dockerfile-maven-issue-repro/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-spotify-docker-repro ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /private/tmp/dockerfile-maven-issue-repro/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-spotify-docker-repro ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /private/tmp/dockerfile-maven-issue-repro/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ maven-spotify-docker-repro ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /private/tmp/dockerfile-maven-issue-repro/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-spotify-docker-repro ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-spotify-docker-repro ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ maven-spotify-docker-repro ---
[INFO] Building jar: /private/tmp/dockerfile-maven-issue-repro/target/application.jar
[INFO]
[INFO] --- dockerfile-maven-plugin:1.3.0:build (default) @ maven-spotify-docker-repro ---
[INFO] Using Google application default credentials
[INFO] loaded credentials for user account with clientId=xxx
[INFO] Building Docker context /private/tmp/dockerfile-maven-issue-repro
[INFO]
[INFO] Image will be built as ashurex/hello-world:latest
[INFO]
[WARNING] An attempt failed, will retry 1 more times
org.apache.maven.plugin.MojoExecutionException: Could not build image
        at com.spotify.plugin.dockerfile.BuildMojo.buildImage(BuildMojo.java:164)
        at com.spotify.plugin.dockerfile.BuildMojo.execute(BuildMojo.java:95)
        at com.spotify.plugin.dockerfile.AbstractDockerMojo.tryExecute(AbstractDockerMojo.java:219)
        at com.spotify.plugin.dockerfile.AbstractDockerMojo.execute(AbstractDockerMojo.java:208)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: com.spotify.docker.client.exceptions.DockerRequestException: Request error: POST unix://localhost:80/build?pull=true&t=ashurex%2Fhello-world%3Alatest: 500, body: {"message":"Cannot locate specified Dockerfile: Dockerfile"}

        at com.spotify.docker.client.DefaultDockerClient.propagate(DefaultDockerClient.java:2387)
        at com.spotify.docker.client.DefaultDockerClient.request(DefaultDockerClient.java:2337)
        at com.spotify.docker.client.DefaultDockerClient.build(DefaultDockerClient.java:1376)
        at com.spotify.docker.client.DefaultDockerClient.build(DefaultDockerClient.java:1348)
        at com.spotify.plugin.dockerfile.BuildMojo.buildImage(BuildMojo.java:157)
        ... 25 more
Caused by: com.spotify.docker.client.shaded.javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
        at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:1020)
        at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:816)
        at org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:92)
        at org.glassfish.jersey.client.JerseyInvocation$5.completed(JerseyInvocation.java:773)
        at org.glassfish.jersey.client.ClientRuntime.processResponse(ClientRuntime.java:198)
        at org.glassfish.jersey.client.ClientRuntime.access$300(ClientRuntime.java:79)
        at org.glassfish.jersey.client.ClientRuntime$2.run(ClientRuntime.java:180)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
        at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:340)
        at org.glassfish.jersey.client.ClientRuntime$3.run(ClientRuntime.java:210)
        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)
[INFO] Using Google application default credentials
[INFO] loaded credentials for user account with clientId=xxx
[INFO] Building Docker context /private/tmp/dockerfile-maven-issue-repro
[INFO]
[INFO] Image will be built as ashurex/hello-world:latest
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.558 s
[INFO] Finished at: 2017-06-23T09:46:42-04:00
[INFO] Final Memory: 33M/326M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.3.0:build (default) on project maven-spotify-docker-repro: Could not build image: Request error: POST unix://localhost:80/build?pull=true&t=ashurex%2Fhello-world%3Alatest: 500, body: {"message":"Cannot locate specified Dockerfile: Dockerfile"}: HTTP 500 Internal Server Error -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@mattnworb I didn't need the **, I was originally copy/pasting the Dockerfile from another project I had laying around that _DID_ need it. What was throwing me off the scent of the ** was that the Docker client itself was interpreting it just fine.

@mattnworb I just updated the readme on the repro repo to explain what you found and describe the situation. Thanks for your help in figuring this out- I was definitely in the 'we need a new pair of eyes' phase of figuring it out.

Just for one more datapoint, the commit at https://github.com/mashurex/dockerfile-maven-issue-repro/commit/9f54b7779a60283491881b39007e233a6d0c8758 builds fine for me via mvn -Pdocker clean package

This is how the .dockerignore file looked

some comments

*
.
.
.

By removing the second line, everything worked as expected.

I had the following problem at my end. In my dockerfile, the maintainer was mis-spelled.
Please debug by trying to build the image using docker build -t .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bverhoeven picture bverhoeven  路  5Comments

beihaifeiwu picture beihaifeiwu  路  7Comments

NancyChunlan picture NancyChunlan  路  12Comments

saturnism picture saturnism  路  7Comments

yangguangftlp picture yangguangftlp  路  6Comments