Madox
Madox

Reputation: 746

Push Docker image to Nexus 3

After starting a Sonatype Nexus 3 image (command 1) I tried to create a repo and push one test image (command 2) to that repo but got an error 405 (error 1)

command 1

$ docker run -d -p 8081:8081 --name nexus sonatype/nexus3:3.14.0

command 2

$ docker push 127.0.0.1:8081/repository/test2/image-test:0.1

error 1

error parsing HTTP 405 response body: invalid character '<' looking for beginning of value: "\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <title>405 - Nexus Repository Manager</title>\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n\n\n  <!--[if lt IE 9]>\n  <script>(new Image).src=\"http://127.0.0.1:8081/favicon.ico?3.14.0-04\"</script>\n  <![endif]-->\n  <link rel=\"icon\" type=\"image/png\" href=\"http://127.0.0.1:8081/favicon-32x32.png?3.14.0-04\" sizes=\"32x32\">\n  <link rel=\"mask-icon\" href=\"http://127.0.0.1:8081/safari-pinned-tab.svg?3.14.0-04\" color=\"#5bbad5\">\n  <link rel=\"icon\" type=\"image/png\" href=\"http://127.0.0.1:8081/favicon-16x16.png?3.14.0-04\" sizes=\"16x16\">\n  <link rel=\"shortcut icon\" href=\"http://127.0.0.1:8081/favicon.ico?3.14.0-04\">\n  <meta name=\"msapplication-TileImage\" content=\"http://127.0.0.1:8081/mstile-144x144.png?3.14.0-04\">\n  <meta name=\"msapplication-TileColor\" content=\"#00a300\">\n\n  <link rel=\"stylesheet\" type=\"text/css\" href=\"http://127.0.0.1:8081/static/css/nexus-content.css?3.14.0-04\"/>\n</head>\n<body>\n<div class=\"nexus-header\">\n  <a href=\"http://127.0.0.1:8081\">\n    <div class=\"product-logo\">\n      <img src=\"http://127.0.0.1:8081/static/images/nexus.png?3.14.0-04\" alt=\"Product logo\"/>\n    </div>\n    <div class=\"product-id\">\n      <div class=\"product-id__line-1\">\n        <span class=\"product-name\">Nexus Repository Manager</span>\n      </div>\n      <div class=\"product-id__line-2\">\n        <span class=\"product-spec\">OSS 3.14.0-04</span>\n      </div>\n    </div>\n  </a>\n</div>\n\n<div class=\"nexus-body\">\n  <div class=\"content-header\">\n    <img src=\"http://127.0.0.1:8081/static/rapture/resources/icons/x32/exclamation.png?3.14.0-04\" alt=\"Exclamation point\" aria-role=\"presentation\"/>\n    <span class=\"title\">Error 405</span>\n    <span class=\"description\">Method Not Allowed</span>\n  </div>\n  <div class=\"content-body\">\n    <div class=\"content-section\">\n      HTTP method POST is not supported by this URL\n    </div>\n      </div>\n</div>\n</body>\n</html>\n\n"

Upvotes: 13

Views: 48683

Answers (2)

juanpb12
juanpb12

Reputation: 145

Nexus Documentation says:

Sharing an image can be achieved by publishing it to a hosted repository. This is completely private and requires you to tag and push the image. When tagging an image, you can use the image identifier (imageId). It is listed when showing the list of all images with docker images. Syntax and an example (using imageId) for creating a tag are:

docker tag <imageId or imageName> <nexus-hostname>:<repository-port>/<image>:<tag>
docker tag af340544ed62 nexus.example.com:18444/hello-world:mytag

Once the tag, which can be equivalent to a version, is created successfully, you can confirm its creation with docker images and issue the push with the syntax:

docker push <nexus-hostname>:<repository-port>/<image>:<tag>

Note that the port needs to be the repository connector port configured for the hosted repository to which you want to push to. You can not push to a proxy repository.

Upvotes: 9

Madox
Madox

Reputation: 746

Explication

After some research I found out that the nexus3 docker repositories are designed to work with individual port for each repository (hosted, group or proxy).

https://issues.sonatype.org/browse/NEXUS-9960

Solution

So I destroyed my previous docker container because I didn't have any relative info on it and launched the same command but with an extra port enabled.

$ docker run -d -p 8081:8081 --name nexus sonatype/nexus3:3.14.0

Updated: need to open port 8082 for docker

$ docker run -d -p 8081:8081 -p 8082:8082 --name nexus sonatype/nexus3:3.14.0

So when you make a new docker repository you need to define at least a http connector port, that I defined in the image as 8082.

nexus3 hosted docker settings

After that you have to login to the service with the default admin account (admin admin123)

$ docker login 127.0.0.1:8082
Username: admin
Password: 
WARNING! Your password will be stored unencrypted in         /home/user/.docker/config.json.
Configure a credential helper to remove this warning. See

https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

Then tried to upload the new tag to that url and it wworked.

$ docker push 127.0.0.1:8082/repository/test2/image-test:0.1
The push refers to repository [127.0.0.1:8082/repository/test2/image-test]
cd76d43ec36e: Pushed 
8ad8344c7fe3: Pushed 
b28ef0b6fef8: Pushed 
0.1: digest: sha256:315f00bd7986508cb0984130bbe3f7f26b2ec477122c9bf7459b0b64e443a232 size: 948

Extra - Dockerfile

So because I needed to create a custom nexus3 docker image for my production environment I started the Dockerfile like this:

FROM sonatype/nexus3:3.14.0

ENV NEXUS_DATA = /nexus-data/

EXPOSE 8090-8099

I will be using the ports from 8090 to 8099 to specify different docker image repositories instead of 8022, but in case I needed more ports I could just change the valors or add a new range of ports.

Hope it was useful!!

Upvotes: 31

Related Questions