简体   繁体   English

Docker - 无法将图像推送到私有注册表

[英]Docker - Unable to push image to private registry

I have created my own private registry on my server by pulling and running the registry image. 我通过拉动和运行注册表图像在我的服务器上创建了自己的私有注册表。

sudo docker run -d -p 5000:5000 registry

After which, I tried to tag a simple image and push it to the server. 之后,我尝试标记一个简单的图像并将其推送到服务器。

sudo docker tag ubuntu:latest localhost:5000/myprivateubuntu

And I received this error: 我收到了这个错误:

Error: Invalid registry endpoint ... Get ... If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add '--insecure-registry localhost: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/localhost:5000/ca.crt

Anyhow know what's the problem? 无论如何知道这是什么问题?

stop the service. 停止服务。

sudo service docker stop

restart service with --insecure-registry arguments: 使用--insecure-registry参数重新启动服务:

/usr/bin/docker -d --insecure-registry localhost:5000

or edit /etc/default/docker file and add the following line: 或编辑/etc/default/docker文件并添加以下行:

DOCKER_OPTS="--insecure-registry localhost:5000"

Setting Local insecure registry in docker along with proxy: 在docker中设置本地不安全注册表以及代理:

1) in ubuntu add the following flag --insecure-registry IP:port under DOCKER_OPTS in file /etc/default/docker 1)在ubuntu中添加以下标志--insecure-registry IP:文件/ etc / default / docker中DOCKER_OPTS下的端口

1.1) configure no_proxy env variable to bypass local IP/hostname/domainname...as proxy can throw a interactive msg ...like continue and this intermediate msg confuses docker client and finally timesout... 1.1)配置no_proxy env变量以绕过本地IP /主机名/域名...因为代理可以抛出交互式消息...就像继续这个中间消息混淆docker客户端并最终超时...

1.2) if domainname is configured...then don't forget to update /etc/hosts file if not using DNS. 1.2)如果配置了域名...那么如果不使用DNS,请不要忘记更新/ etc / hosts文件。

1.3) in /etc/default/docker set the env variables http_proxy and https_proxy...as it enables to download images from outside company hubs. 1.3)在/ etc / default / docker中设置env变量http_proxy和https_proxy ...因为它可以从公司外部中心下载图像。 format http_proxy= http://username:password@proxy:port 格式为http_proxy = http:// username:password @ proxy:port

2) restart the docker service...if installed as service, use sudo service docker restart 2)重启docker服务...如果安装为服务,请使用sudo service docker restart

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

4) tag the required image using sudo docker tag imageid IP:port/imagename/tagname ifany 4)使用sudo docker tag imageid标记所需的图像IP:port / imagename / tagname ifany

5) push the image ...sudo docker push ip:port/imagename 5)推送图像... sudo docker push ip:port / imagename

6) If u want to pull the image from another machine say B without TLS/SSL,then in B apply setps 1,1.1 and 2. If these changes are not done in machine B...pull will fail. 6)如果你想从另一台机器拉出图像说B没有TLS / SSL,那么在B中应用setps 1,1.1和2. 如果这些改变没有在机器B中完成...拉动将失败。

From comments of the accepted answer, it looks like the solution does not works for all. 根据接受的答案的评论,看起来解决方案并不适用于所有人。 The following solution works for me. 以下解决方案适合我。

Create systemd conf override file for Docker 为Docker创建systemd conf覆盖文件

sudo mkdir /etc/systemd/system/docker.service.d
sudo touch /etc/systemd/system/docker.service.d/docker.conf
sudo vi /etc/systemd/system/docker.service.d/docker.conf

Add these following line and save it 添加以下行并保存

[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// $DOCKER_OPTS
EnvironmentFile=-/etc/default/docker

Edit /etc/default/docker 编辑/etc/default/docker

sudo vi /etc/default/docker

Add the following line and save it. 添加以下行并保存。 Replace localhost:5000 with your registry domain name and port localhost:5000替换为您的注册表域名和端口

DOCKER_OPTS="--insecure-registry localhost:5000"

Restart docker daemon 重启docker守护进程

Reload overriden configuration and restart docker as follows 重新加载覆盖配置并重新启动docker ,如下所示

sudo systemctl daemon-reload
sudo systemctl restart docker 

My solution, built on top of the prior ones. 我的解决方案建立在之前的解决方案之上。

# docker -v
Docker version 18.09.1, build 4c52b90
# uname -a
Linux host 4.15.0-43-generic #46~16.04.1-Ubuntu SMP Fri Dec 7 13:31:08 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Contents of my /etc/docker/daemon.json file: 我的/etc/docker/daemon.json文件的内容:

{
    "runtimes": {
        "nvidia": {
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
        }
    },
    "insecure-registries" : [
        "ipaddress:port"
      ],
    "experimental" : false,
    "debug" : true
}

where ipaddress:port is the dotted IPv4 address of the registry machine followed by the registry port (eg 127.0.0.1:12345 ). 其中ipaddress:port是注册表机器的虚线IPv4地址,后跟注册表端口(例如127.0.0.1:12345 )。 I did not have to prefix with http:// or anything like that. 我不需要用http://或类似的东西作为前缀。

No changes to /etc/default/docker 没有更改/etc/default/docker

And then I reloaded and restarted the daemon with: 然后我重新加载并重新启动守护进程:

# sudo systemctl daemon-reload
# sudo systemctl restart docker

docker push to the insecure registry works now. docker push送到不安全的注册表现在工作。

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

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