5
votes

I am building a development pipeline. The Docker images will be created automatically after a successful and tested version of my java application be deployed on a private Maven repository (Sonatype Nexus).

Once my application is built successfully, I need to publish it in somewhere, and Docker needs to have access to download it and create a container.

I thought on Docker accessing the Nexus Maven repository, but I did not find how can wget download a jar from a private repository. I did not found on Nexus documentation how I can pass authentication parameters to access a private URL. Does anyone know that?

PS: I also accept advice of easier solutions to accomplish this.

2
What do you mean by private repository? Do you have access to it from Docker while building?gmaslowski
Its a private Sonatype Nexus Repository. Needs user and password to access it.John John Pichler

2 Answers

3
votes

I just discovered I can do it using cURL. Example:

curl -u username:password -o myapp.war "http://nexus.mycompany.com/service/local/artifact/maven/redirect?r=snapshots&g=com.company&a=MyApp&v=1.0-SNAPSHOT&p=war" -L

Where de -L flag is to cURL accepts redirect (301 response).

So, in docker-compose.yml I have a line like this:

RUN curl -u username:password -o myapp.war "http://nexus.mycompany.com/service/local/artifact/maven/redirect?r=snapshots&g=com.company&a=MyApp&v=1.0-SNAPSHOT&p=war" -L
1
votes

If you are using maven

mvn dependency:copy -Dartifact=groupId:artifactId:version[:packaging][:classifier] -DoutputDirectory=[target] -Dusername=[username] -Dpassword=[password]