Maven inside docker container horribly slow Maven inside docker container horribly slow docker docker

Maven inside docker container horribly slow


I ran into this same issue using the same docker run syntax as you (docker run -v src:dest). A Maven build that took ~30 seconds on my OSX host was taking ~4 minutes in my container. I didn't solve it entirely, but switching to explicitly use a bind mount took my builds from around 4 minutes down to about 1.5 minutes. This still isn't an acceptable increase in build time for my use case, but it may help someone else. Try switching your docker run command to this:

docker run --name=my-maven-project -it \ --mount type=bind,source="$(pwd)",destination=/usr/src/app,consistency=delegated <docker image name>

NOTE: The consistency option at the very end is only valid on OSX, and has two other values, either of which may be more appropriate for your situation. I tried all three out of curiosity and build times were comparable between the delegated and cached options, meanwhile the consistent option nearly as slow as the way I was doing it before (unsurprisingly). Here's the documentation:

https://docs.docker.com/storage/bind-mounts/

So, unfortunately, despite bind mounts being "very performant," they're still apparently at least twice as slow as a native filesystem when it comes to maven builds, at least on OSX. With luck that will improve as time goes on.