将Docker映像推送到Nexus 3

Mad*_*dox 1 nexus sonatype docker nexus3

启动Sonatype Nexus 3映像(命令1)后,我尝试创建一个存储库并将一个测试映像(命令2)推送到该存储库,但出现错误405(错误1)

命令1

$ docker run -d -p 8081:8081 --name nexus sonatype/nexus3:3.14.0
Run Code Online (Sandbox Code Playgroud)

命令2

$ docker push 127.0.0.1:8081/repository/test2/image-test:0.1
Run Code Online (Sandbox Code Playgroud)

错误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"
Run Code Online (Sandbox Code Playgroud)

小智 9

Nexus 文档说:

可以通过将图像发布到托管存储库来实现共享图像。这是完全私有的,需要您标记并推送图像。标记图像时,可以使用图像标识符 (imageId)。显示带有 docker 镜像的所有镜像的列表时会列出它。创建标签的语法和示例(使用 imageId)如下:

docker tag <imageId or imageName> <nexus-hostname>:<repository-port>/<image>:<tag>
docker tag af340544ed62 nexus.example.com:18444/hello-world:mytag
Run Code Online (Sandbox Code Playgroud)

成功创建相当于版本的标签后,您可以使用 docker 镜像确认其创建,并使用以下语法发出推送:

docker push <nexus-hostname>:<repository-port>/<image>:<tag>
Run Code Online (Sandbox Code Playgroud)

请注意,该端口需要是为要推送到的托管存储库配置的存储库连接器端口。您无法推送到存储库组或代理存储库。

希望对您有帮助!


Mad*_*dox 7

解释

经过研究后,我发现nexus3 docker存储库旨在与每个存储库(托管,组或代理)的单个端口一起使用。

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

解

所以我销毁了先前的Docker容器,因为我没有任何相对信息,并启动了相同的命令,但启用了额外的端口。

$ docker run -d -p 8081:8081 --name nexus sonatype/nexus3:3.14.0
Run Code Online (Sandbox Code Playgroud)

因此,当您创建新的docker存储库时,您需要至少定义一个http连接器端口,我在镜像中将其定义为8082。

nexus3托管的docker设置

之后,您必须使用默认管理员帐户(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
Run Code Online (Sandbox Code Playgroud)

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

Login Succeeded
Run Code Online (Sandbox Code Playgroud)

然后尝试将新标签上传到该网址,然后它起作用了。

$ 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
Run Code Online (Sandbox Code Playgroud)

额外-Dockerfile

因此,因为我需要为生产环境创建自定义的nexus3 docker映像,所以我启动了Dockerfile,如下所示:

FROM sonatype/nexus3:3.14.0

ENV NEXUS_DATA = /nexus-data/

EXPOSE 8090-8099
Run Code Online (Sandbox Code Playgroud)

我将使用从8090到8099的端口来指定不同的docker映像存储库,而不是8022,但是如果我需要更多端口,则可以更改valors或添加新的端口范围。

希望它有用!!