如何远程访问私有Docker仓库?

84

我正在尝试使用从https://github.com/docker/docker-registry获取的镜像建立一个私有Docker注册表。

只需运行以下命令:
docker run -p 5000:5000 registry

我只能在本地主机上从该存储库中拉取/推送,但如果我尝试从另一台机器(使用同一局域网下的私有地址)访问它,则会出现错误信息。

*2014/11/03 09:49:04 Error: Invalid registry endpoint https ://10.0.0.26:5000/v1/': 
Get https:// 10.0.0.26:5000/v1/_ping: Forbidden. If this private 
registry supports only HTTP or HTTPS with an unknown CA certificate,
please add `--insecure-registry 10.0.0.26:5000` to the daemon's 
arguments. In the case of HTTPS, if you have access to the registry's
CA certificate, no need for the flag; simply place the CA certificate 
at /etc/docker/certs.d/10.0.0.26:5000/ca.crt*

让我感到疯狂的是,我可以使用以下命令成功访问它: curl 10.0.0.26:5000 和/或 curl 10.0.0.26:5000/v1/search

同时,我也不明白在哪里以及如何传递--insecure-registry标志。


3
许多答案似乎已经过时了,不适用于Docker 1.12版本,但请参考vikas027的回答,这对Docker 1.12非常有用(截至最新版本)。 - danday74
1
在Ubuntu上,Docker文档这个答案对我很有帮助。 - Batandwa
15个回答

1

这是基于vikas027在Centos 7和Docker 1.12上的答案。

由于我在代理后面,我的完整解决方案是...

/etc/systemd/system/docker.service.d/http-proxy.conf

[Service]

Environment="FTP_PROXY={{MY_PROXY}}"
Environment="ftp_proxy={{MY_PROXY}}"

Environment="HTTPS_PROXY={{MY_PROXY}}"
Environment="https_proxy={{MY_PROXY}}"

Environment="HTTP_PROXY={{MY_PROXY}}"
Environment="http_proxy={{MY_PROXY}}"

Environment="NO_PROXY=localhost,127.0.0.1,{{MY_INSECURE_REGISTRY_IP}}"
Environment="no_proxy=localhost,127.0.0.1,{{MY_INSECURE_REGISTRY_IP}}"

/usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd --insecure-registry {{MY_INSECURE_REGISTRY_IP}}:5000

不要忘记重新启动 :)
sudo systemctl daemon-reload; sudo systemctl restart docker;

1
“--insecure-registry” 是一种解决方法而不是修复方法。 - peterh

0

0

在Docker中设置本地不安全的注册表和代理:

1)在Ubuntu中,在文件/etc/default/docker的DOCKER_OPTS下添加以下标志--insecure-registry IP:port

1.1)配置no_proxy环境变量以绕过本地IP/主机名/域名......因为代理可能会抛出交互式消息...如继续等待,这会使Docker客户端困惑并最终超时...

1.2)如果已配置域名...则不要忘记更新/etc/hosts文件(如果不使用DNS)。

1.3)在/etc/default/docker中设置环境变量http_proxy和https_proxy...因为这样可以从公司外部的中心下载镜像。 格式http_proxy=http://username:password@proxy:port

2)重新启动Docker服务...如果已安装为服务,请使用sudo service docker restart

3)重新启动注册表容器[sudo docker run -p 5000:5000 registry:2]

4)使用sudo docker tag imageid IP:port/imagename/tagname(如果有)标记所需的映像

5)推送映像... sudo docker push ip:port/imagename

6) 如果你想从另一台没有TLS/SSL的机器B上拉取图像,则在B上执行步骤1、1.1和2。 如果在机器B上没有进行这些更改... 拉取将失败。


2
“--insecure-registry” 是一种解决方法而不是修复方法。 - peterh

0
除了以上的答案,我还想补充一下在我的“docker for mac”中有效的方法:
  1. 从屏幕右上角的Mac托盘中单击Docker鲸标
  2. 单击首选项 -> 守护程序
  3. 将您的IP和端口添加到不安全的注册表中。
  4. 重新启动守护程序。

enter image description here


0

Ubuntu 16.04

创建(如果不存在)文件/etc/systemd/system/docker.service.d/registry.conf,并填入以下内容:

[Service]
#You need the below or you 'ExecStart=' or you will get and error 'Service has more than one ExecStart= setting, which is only allowed'
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// --insecure-registry 10.20.30.40:5000

那么

sudo systemctl stop docker
sudo systemctl daemon-reload
sudo systemctl start docker

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接