All Articles

Docker Build for Maven behind a proxy

Recently I had to build a Dockerfile using the Maven image behind a proxy. The docker configuration for the proxy was correct (using this link) and working but for some reason the dependencies were not resolved and it failed.

Even setting the proxy configuration in the Dockerfile failed.

The solution was to send the proxy params in the build command for both the runtime and the MAVEN_OPTS environment variable. Something like this:

$ docker build -t awesome_image --build-arg http_proxy=http://proxy:9090 --build-arg https_proxy=http://proxy:9090 --build-arg MAVEN_OPTS="-Dhttp.proxyHost=proxy -Dhttp.proxyPort=9090 -Dhttps.proxyHost=proxy -Dhttps.proxyPort=9090" 

This fixed the issue.

As always, to be behind a proxy requires you to always think about that wall and take into account that each of the layers that you are interacting are correctly using to the proxy.