简体   繁体   English

无法将docker镜像推送到本地OpenShift Origin注册表

[英]Unable to push a docker image to local OpenShift Origin registry

The goal is to be able take a Docker image on my laptop and push it to the OpenShift Origin image registry (started by oc cluster up ) to do local development. 目标是能够在我的笔记本电脑上获取Docker镜像并将其推送到OpenShift Origin图像注册表(由oc cluster up )进行本地开发。 It's not clear if I'm doing something wrong or there's a bug in Docker or OpenShift Origin. 目前尚不清楚我是在做错事还是在Docker或OpenShift Origin中存在错误。 For those unfamiliar with OpenShift Origin: 对于那些不熟悉OpenShift Origin的人:

https://github.com/openshift/origin/blob/master/docs/cluster_up_down.md https://github.com/openshift/origin/blob/master/docs/cluster_up_down.md

Any illuminating information would be appreciated. 任何有启发性的信息将不胜感激。 Here's what I've tried so far: 这是我到目前为止所尝试的:

# oc cluster up
Starting OpenShift using openshift/origin:v3.6.0 ...
OpenShift server started.

The server is accessible via web console at:
    https://127.0.0.1:8443

You are logged in as:
    User:     developer
    Password: <any value>

To login as administrator:
    oc login -u system:admin

# docker container ls | fgrep origin-docker-registry
9de6bb0cdd28        openshift/origin-docker-registry   "/bin/sh -c '/usr/..."

# docker inspect 9de6bb0cdd28 | fgrep DOCKER_REGISTRY_PORT
                "DOCKER_REGISTRY_PORT_5000_TCP_PROTO=tcp",
                "DOCKER_REGISTRY_PORT=tcp://172.30.1.1:5000",
                "DOCKER_REGISTRY_PORT_5000_TCP_PORT=5000",
                "DOCKER_REGISTRY_PORT_5000_TCP_ADDR=172.30.1.1",
                "DOCKER_REGISTRY_PORT_5000_TCP=tcp://172.30.1.1:5000",

# oc whoami -t
qH2cTKtIpr1QB1dMw10ffiDGX1iH_uocrtXaFPyTei8    

# docker login -u developer -p qH2cTKtIpr1QB1dMw10ffiDGX1iH_uocrtXaFPyTei8 172.30.1.1:5000
Login Succeeded

# docker tag alpine:latest 172.30.1.1:5000/alpine:latest

# docker push 172.30.1.1:5000/alpine:latest
The push refers to a repository [172.30.1.1:5000/alpine]
5bef08742407: Preparing 
error parsing HTTP 400 response body: unexpected end of JSON input: ""

I know that running alpine won't yield anything interesting. 我知道跑阿尔卑斯山不会产生任何有趣的东西。 The result is the same regardless of what image I try to push. 无论我试图推送什么图像,结果都是一样的。 The login seems to actually work. 登录似乎确实有效。 If I remove or alter any part of the token, the login fails. 如果我删除或更改令牌的任何部分,登录将失败。 The version of Docker I'm running: 我正在运行的Docker版本:

# docker version
Client:
 Version:      17.06.0-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:31:53 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.06.0-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:51:55 2017
 OS/Arch:      linux/amd64
 Experimental: true

There are potentially a couple of issues which can affect when trying to push docker images. 尝试推送泊坞窗图像时可能会影响一些问题。

Before we get to that, usually the way to give access to the internal image registry would be to expose it using a route. 在我们开始之前,通常允许访问内部图像注册表的方法是使用路由公开它。 Since using an IP as you were only applies to oc cluster up , will show how to use a route instead, that way more generic. 由于您使用的IP仅适用于oc cluster up ,因此将显示如何使用路由,这种方式更通用。

For oc cluster up , you would run: 对于oc cluster up ,您将运行:

oc expose svc/docker-registry -n default --as system:admin

This would create a URL for the internal image registry of: 这将为内部图像注册表创建一个URL:

http://docker-registry-default.127.0.0.1.nip.io/

Next login to the internal image registry using: 下次使用以下命令登录内部图像注册表:

docker login -u developer -p `oc whoami -t` http://docker-registry-default.127.0.0.1.nip.io:80/

Make sure you use :80 in the URL when you login. 登录时,请确保在URL中使用:80 If the internal image registry was exposed using a secure route, would instead use :443 instead of :80 . 如果使用安全路由公开内部图像注册表,则使用:443而不是:80

Next you want to tag the image, but do be careful what you tag it with, as you want to include the project name in which the image stream should be added. 接下来,您要标记图像,但要注意标记它的内容,因为您要包含应添加图像流的项目名称。

docker tag alpine:latest docker-registry-default.127.0.0.1.nip.io:80/myproject/alpine

See how I included myproject in tag, as that is the project I wanted it to end up in. 看看我如何将myproject包含在标记中,因为这是我希望它最终完成的项目。

Details in: 详细信息:

Again use :80 for the port in the name. 再次使用:80为名称中的端口。 That need the port in the URL when logging in, even though http given, may be a bug in 3.6.0 or docker command line client. 登录时需要URL中的端口,即使http给出,可能是3.6.0或docker命令行客户端中的错误。 They mention this against OpenShift Online at the moment, which is using 3.6.0. 他们目前在OpenShift Online上提到这一点,它使用的是3.6.0。

Now can push the image: 现在可以推送图像:

docker push docker-registry-default.127.0.0.1.nip.io:80/myproject/alpine

Full sequence of commands is: 完整的命令序列是:

$ oc expose svc/docker-registry -n default --as system:admin
route "docker-registry" exposed

$ docker login -u developer -p `oc whoami -t` http://docker-registry-default.127.0.0.1.nip.io:80/
Login Succeeded

$ docker tag alpine:latest docker-registry-default.127.0.0.1.nip.io:80/myproject/alpine

$ docker push docker-registry-default.127.0.0.1.nip.io:80/myproject/alpine
The push refers to a repository [docker-registry-default.127.0.0.1.nip.io:80/myproject/alpine]
5bef08742407: Layer already exists
latest: digest: sha256:471fd6e70d36b9c221f76464d0a9ff78392ccee359da351ebfec45138fb40f9b size: 528

$ oc get is
NAME      DOCKER REPO                        TAGS      UPDATED
alpine    172.30.1.1:5000/myproject/alpine   latest    10 seconds ago

You can, like Graham pointed out above expose the registry, but it's not required. 您可以像Graham上面指出的那样公开注册表,但这不是必需的。

In your case when using internal IP, the docker push command docker push 172.30.1.1:5000/alpine:latest is not correct. 在使用内部IP的情况下, docker push 172.30.1.1:5000/alpine:latest push命令docker push 172.30.1.1:5000/alpine:latest不正确。 In either case (external route or internal IP) the internal registry, based on the image namespace and name, will create appropriate image stream for you. 在任何一种情况下(外部路由或内部IP),内部注册表(基于图像命名空间和名称)将为您创建适当的图像流。 The name of the image stream and the namespace/project for it, is taken from the push. 图像流的名称和它的名称空间/项目取自推送。 This means you need to make sure you tag the image with 3 elements: 这意味着您需要确保使用3个元素标记图像:

  • docker registry IP and port (external route or internal IP) docker注册表IP和端口(外部路由或内部IP)
  • namespace/project your user have access to (in case of oc cluster up myproject is the default one your user have access to) 您的用户有权访问的命名空间/项目(如果是oc cluster up myproject是您的用户可以访问的默认值)
  • finally the image stream name 最后是图像流名称

In your case the docker push should look like this: docker push 172.30.1.1:5000/myproject/alpine:latest . 在你的情况下, docker push 172.30.1.1:5000/myproject/alpine:latest push应如下所示: docker push 172.30.1.1:5000/myproject/alpine:latest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM