首页 > 解决方案 > 如何从 docker hub 部署到 openshift?

问题描述

我正在尝试在 openshift 上从 docker hub 部署一个 docker 映像。

我用一个简单的 Spring Boot Rest 应用程序创建了一个图像: https ://hub.docker.com/r/ernst1970/my-rest

登录到 openshift 并选择我做的正确项目后

oc new-app ernst1970/my-rest

我得到

W0509 13:17:28.781435   16244 dockerimagelookup.go:220] Docker registry lookup failed: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Clien
t.Timeout exceeded while awaiting headers)                                                                                                                                                 
error: Errors occurred while determining argument types:                                                                                                                                   

ernst1970/my-rest as a local directory pointing to a Git repository:  GetFileAttributesEx ernst1970/my-rest: The system cannot find the path specified.                                    

Errors occurred during resource creation:                                                                                                                                                  
error: no match for "ernst1970/my-rest"                                                                                                                                                    

The 'oc new-app' command will match arguments to the following types:                                                                                                                      

  1. Images tagged into image streams in the current project or the 'openshift' project                                                                                                    
     - if you don't specify a tag, we'll add ':latest'                                                                                                                                     
  2. Images in the Docker Hub, on remote registries, or on the local Docker engine                                                                                                         
  3. Templates in the current project or the 'openshift' project                                                                                                                           
  4. Git repository URLs or local paths that point to Git repositories                                                                                                                     

--allow-missing-images can be used to point to an image that does not exist yet.                                                                                                           

See 'oc new-app -h' for examples.                                                                                                                                                          

我也试过

oc new-app mariadb

但是得到了同样的错误信息。

我认为这可能是代理问题。所以我将代理添加到我的.profile

export http_proxy=http://ue73011:secret@dev-proxy.wzu.io:3128
export https_proxy=http://ue73011:secret@dev-proxy.wzu.io:3128

不幸的是,这并没有改变任何东西。

任何想法为什么这不起作用?

标签: dockeropenshiftdockerhub

解决方案


您的 docker 守护进程需要代理才能访问 DockerHub。您可以通过将代理服务器作为 docker 守护程序的环境变量来指定它。

看看官方的 Docker 文档:https ://docs.docker.com/config/daemon/systemd/

sudo mkdir -p /etc/systemd/system/docker.service.d

添加一个文件/etc/systemd/system/docker.service.d/http-proxy.conf应该包含以下内容

[Service]    
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,docker-registry.example.com,.corp"

重新加载您的更改并重新启动 docker daemon

sudo systemctl daemon-reload
sudo systemctl restart docker

通过执行简单的“docker pull ...”进行验证


推荐阅读