Reputation: 3217
I am a docker maven plugin newbie.
If I understand well, according to Spotify's Dockerfile Maven documentation, one should place the Dockerfile on the root directory of my project (I'm running a spring boot project).
In making a reference to docker's Best practices for writing Dockerfiles:
Regardless of where the Dockerfile actually lives, all of the recursive contents of files and directories in the current directory are sent to the Docker daemon as the build context. Inadvertently including files that are not necessary for building the image results in a larger build context and larger image size.
Does that mean that when the Spotify Dockerfile Maven plugin runs the configuration I am exposing my source folder which is sent to docker daemon?
Upvotes: 2
Views: 4614
Reputation: 16110
By default, yes the build context will include your source (and your target) directory. But, you can add a .dockerignore
file that tells it not to do this.
If you're not sure what this is, take a look at this tutorial.
IMO: I can imagine scenarios where running docker from maven would be the right thing to do. However, my imagination is very good and there can't be that many shops that are adopting docker but not changing their legacy maven build pipelines.
In the majority of cases though, you don't want to do this.
Rather, you should use one docker container to build the java artifact and run the unit-tests. This can then push the artifact to nexus (or whatever repo you're using). If this is a webapp or other http service, then you can use a second container to host it and deploy this to an environment to integration test it.
Upvotes: 1