spotify / dockerfile-maven

MATURE: A set of Maven tools for dealing with Dockerfiles
Apache License 2.0
2.75k stars 493 forks source link

Very slow #362

Closed ptahchiev closed 4 years ago

ptahchiev commented 4 years ago

So I have the following layout (super standard maven build):

 - pom.xml
      - src/main/docker/Dockerfile
            - many more files/folders in src
      - target/myapp.jar

I have configured the dockerfile-maven-plugin as such:

            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <configuration>
                    <buildArgs>
                        <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
                    </buildArgs>
                    <contextDirectory>${basedir}</contextDirectory>
                    <dockerfile>src/main/docker/Dockerfile</dockerfile>
                    <noCache>true</noCache>
                    <repository>nemesis/${project.artifactId}</repository>
                </configuration>
            </plugin>

now when I run mvn dockerfile:build every time it takes 2 minutes before it even start building the image!!!!! I think it is because it tries to add all the files in . as . is my contextDirectory. But I have no other option - my Dockerfile is in src and my .jar file is in target so my only option is to have the contextDirectory as .. Am I right? How can I make it faster?

mattnworb commented 4 years ago

try adding a .dockerignore file to reduce the amount of files that have to be sent to your docker daemon in order to build an image

ptahchiev commented 4 years ago

I'll give it a try, although it looks dumb - I have to virtually exclude every single file besides the target/app.jar. The better solution would be to include the target/app.jar and by default have everything excluded. This contextDirectory is super stupid idea.

mattnworb commented 4 years ago

Well the stupid idea is all on Docker's side, it will send everything in your "context" to the daemon so it can build an image out of your Dockerfile unless you explicitly tell it to ignore stuff. If you take a look at the docs, you can put something in your .dockerignore file like:

target
!target/app.jar

to ignore everything under target except a given path