3

New to nexus.. We are trying to automate build process (Build docker images and publish them to Nexus3 repository).. My requirement is, I have an image built using docker build -t <imagename>:<version> . now I want to publish this docker image to nexus repo using Jenkins.

I have a nexus repo and Jenkins Job is configured with docker-maven plugin also I have provided docker:push maven target.. Not sure how to push now? Do I need to use shell script with docker push <imagename>:<version> or what steps I have to mention in Jenkins CI job.

Please help me..

rameshthoomu
  • 1,234
  • 2
  • 17
  • 33

1 Answers1

2

From the question it is not clear whether you have set up Nexus Docker Registry or Nexus Maven Repository. You wrote about "Nexus Repo", which implies Nexus Maven Repo.

If you mean Nexus Maven Repository...

Docker stores images into a Docker server. It connects to it using it's own protocol. Nexus is a different paradigm and not compatible as is.

Docker Maven Plugin's push goal pushes to a remote Docker repository, e.g. DockerHub, or GitLab. That is different from "deploying" Maven artifacts to Nexus.

Docker allows to get an image in a form of a .tar file using docker load. Maybe someone created some kind of "wagon", a thing that would to allow maven to "resolve" these files which you would declare as dependencies. But the whole idea is probably not really advisable following. As I said, Maven and Docker's approaches are different.

Edit: So it turns out that somebody did - and it was the creators of Nexus. As pointed out by @masseyb. But after quick reading, it turns out that it's just a normal Docker registry, just branded and and bundled with Nexus. I assume that the poster asked about how to use Nexus Maven repository to store Docker images.

If you have the Nexus Docker registry...

then you need to:

  • Set up D-M-P, using the credentials set up in Nexus.
    I think you can also docker login to that; before running Maven.
  • Set the repository ID as prefix in <name> of the <image>.
  • The push goal will then push to that repository.

This article about using multiple registries may come handy, too.

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
  • Downvoted because nexus can be configured as a [docker registry](https://help.sonatype.com/repomanager3/formats/docker-registry). – masseyb Aug 14 '19 at 05:53
  • OP can create a hosted docker repository in nexus (eventually add a reverse proxy in front of it), tag the images with the server name (needs to be resolved) and use the docker:push maven target to push the images. Upvoted edited answer. – masseyb Aug 14 '19 at 06:05
  • From the question it is not clear that the OP uses Nexus Docker Registry. He writes about Nexus Repo, which implies Nexus Maven Repo. – Ondra Žižka Aug 14 '19 at 06:06
  • 1
    I agree, my understanding ref. the mention of “I have also provided [docker:push](http://dmp.fabric8.io/#docker:push) maven target” is that OP is trying to push the images to his own docker registry hosted in nexus. – masseyb Aug 14 '19 at 06:11
  • A side note that `nexus3` does a lot tbh (ref. your mention "which implies Nexus Maven Repo"). We use it as our `docker` hosted (internal) registry and proxy, `pypi`, `apt`, `npm`, ... – masseyb Aug 14 '19 at 06:52
  • I understand, we also use it as storage for all kinds of files, and it is really cool. But for Docker images, the standard Nexus Maven approach with G:A:V is not applicable well, IMHO. – Ondra Žižka Aug 14 '19 at 07:47