Docker-maven-plugin: A tar file cannot include itself

Created on 25 Feb 2016  路  13Comments  路  Source: fabric8io/docker-maven-plugin

Here's my project structure

/base$ ls -al
total 32
drwxrwxr-x  4 arthur arthur 4096 Feb 25 10:46 .
drwxrwxr-x 17 arthur arthur 4096 Feb 24 16:07 ..
-rw-rw-r--  1 arthur arthur  752 Feb 25 10:46 Dockerfile
drwxrwxr-x  8 arthur arthur 4096 Feb 25 10:46 .git
-rw-rw-r--  1 arthur arthur    8 Jan 22 15:00 .gitignore
-rw-rw-r--  1 arthur arthur 1924 Feb 25 10:46 pom.xml
-rw-rw-r--  1 arthur arthur   53 Jan 22 15:00 Readme.md
drwxrwxr-x  4 arthur arthur 4096 Feb 25 10:39 target

and the pom file has

            <plugin>
                <groupId>io.fabio8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.14.0</version>
                <configuration>
                    <registry>myregistry.com</registry>
                    <images>
                        <image>
                            <alias>base</alias>
                            <name>base:${project.version}</name>
                            <build>
                                <assembly>
                                    <dockerFileDir>${project.basedir}</dockerFileDir>
                                </assembly>
                            </build>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>docker</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>registry</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>push</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

the same setup works in 0.13.9 but get this starting 0.14.0

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.14.0:build (docker) on project nodejs: Execution docker of goal io.fabric8:docker-maven-plugin:0.14.0:build failed: A tar file cannot include itself. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal io.fabric8:docker-maven-plugin:0.14.0:build (docker) on project nodejs: Execution docker of goal io.fabric8:docker-maven-plugin:0.14.0:build failed: A tar file cannot include itself.

thanks.

Most helpful comment

Sorry, forgot that there is already support for a .maven-dockerignore which can contain ant style patterns for excluding directories.

So adding a .maven-dockerignore with the content

target/**

will avoid the inclusion of the target directory.

Does this work for you ?

All 13 comments

The reason could be the update of the Maven assembly plugin to the newest version 2.6 which fixes some bugs, especially when used on Windows. It's the assembly plugin which is responsible for tarring up stuff which then is sent to the Docker daemon.

I guess, that in your .dockerignore you have .git and target included, right ?

If you look in target/docker/base/<version>/tmp you see a tar file when using 0.13.9. Could you post what is contained in this tar ?

I suggest to implement a filter which takes care of a .dockerignore when present so that target/ can be left out in the tar.

I just rebuild your setup and in fact when using 0.13.9 the tar file created looks like

tar tvf target/docker/dmp-sample/toplevel-dockerfile/tmp/docker-build.tar
drwxr-xr-x  0 roland staff       0 Feb 25 21:12 target/
drwxr-xr-x  0 roland staff       0 Feb 25 21:12 target/docker/
drwxr-xr-x  0 roland staff       0 Feb 25 21:12 target/docker/dmp-sample/
drwxr-xr-x  0 roland staff       0 Feb 25 21:12 target/docker/dmp-sample/toplevel-dockerfile/
drwxr-xr-x  0 roland staff       0 Feb 25 21:12 target/docker/dmp-sample/toplevel-dockerfile/build/
drwxr-xr-x  0 roland staff       0 Feb 25 21:12 target/docker/dmp-sample/toplevel-dockerfile/tmp/
drwxr-xr-x  0 roland staff       0 Feb 25 21:12 target/docker/dmp-sample/toplevel-dockerfile/work/
-rw-r--r--  0 roland staff      13 Feb 25 21:09 Dockerfile
-rw-r--r--  0 roland staff    1246 Feb 25 21:11 pom.xml
-rw-r--r--  0 roland staff       0 Feb 25 21:12 target/docker/dmp-sample/toplevel-dockerfile/tmp/docker-build.tar

So in fact with 0.13.9 the tar file includes itself which correctly can be considered a bug which is fixed in this maven-assembly plugin version leading to the error message you see.

Of course you could always rearrange your directory hierarchy to not include the target directory (e.g. in the classical maven style somewhere below src/).

I opened #398 for support of a .dockerignore which would help here as well.

Sorry, forgot that there is already support for a .maven-dockerignore which can contain ant style patterns for excluding directories.

So adding a .maven-dockerignore with the content

target/**

will avoid the inclusion of the target directory.

Does this work for you ?

it works! thanks. btw, target/docker/** works too.

sorry Mr rhuss i don't where should i put .maven-dockerignore

@StevesRoger Put it into your projects base directory See next comment for the correct answer.

@StevesRoger Sorry, I meant the the directory where your dockeFileDir is pointing to (e.g. src/main/docker). But this is explained in the docs.

Thanks to @arthurtsang for the suggestion of add target/docker/**. If I put target/** into my .maven-dockerignore when the image is built throws an exception due to jar file is missing.

Actually, since version 0.25.2, target/docker/** should be added by default, so no need for adding a .maven-dockerignore for this purpose anymore.

Thanks @rhuss for your advice. Perhaps, I still need to add .maven-dockerignore file with 0.26.0 version as you can see below:

image

Experiencing this issue on 0.28.0
I tried explicitly adding .maven-dockerignore with target/docker/** but to no avail.
Still getting Execution build-docker-images of goal io.fabric8:docker-maven-plugin:0.28.0:build failed: A tar file cannot include itself

Config:

<image>
  <alias>webapp</alias>
  <name>${DOCKER_REGISTRY}${project.name}/${project.artifactId}:${project.version}</name>
  <build>
    <dockerFile>${project.parent.basedir}/Dockerfile</dockerFile>
  </build>
  <run>
    <links>
      <link>postgres</link>
    </links>
    <ports>8080:8080</ports>
    <log>
      <color>CYAN</color>
    </log>
  </run>
</image>

Did you typo .docker-mavenignore in the issue comment, or is that what you're actually using in your project? It's .maven-dockerignore - maven comes first in the filename.

Did you typo .docker-mavenignore in the issue comment, or is that what you're actually using in your project? It's .maven-dockerignore - maven comes first in the filename.

Typo indeed, fixed it.

Was this page helpful?
0 / 5 - 0 ratings