Docker push 失败解决办法

910 阅读1分钟

一、问题背景

Docker将本地的镜像上传到镜像仓库时,有时候发生如下的报错:

[root@Test sysconfig]# docker push 192.168.1.100:5000/hello-test:2.4.1

The push refers to a repository [192.168.1.100:5000/hello-test]

Get https://192.168.1.100:5000/v1/_ping: http: server gave HTTP response to HTTPS client

这个问题可能是由于客户端采用https,docker registry未采用https服务所致。一种处理方式是把客户对地址“192.168.1.100:5000”请求改为http。

目前很多文章都是通过修改docker的配置文件“/etc/sysconfig/docker",重启docker来解决这个问题。但发现docker1.12.3版本并无此文件,根据网上创建此文件,并填入相应内容,重启docker无效果,仍然报此错误。

二、解决办法

2.1、创建daemon.json文件

在”/etc/docker/“目录下,创建”daemon.json“文件。在文件中写入:

{ "insecure-registries":["192.168.1.100:5000"] }

注:这个json文件中的私有仓库地址可以配置多个。

保存退出后,重启docker。

[root@Test sysconfig]# dockerd --insecure-registry 192.168.1.100:5000

[root@Test sysconfig]# vim /etc/default/docker

增加以下一行:

DOCKER_OPTS="$DOCKER_OPTS --insecure-registry=192.168.1.100:5000"

2.2、 重启Docker

[root@Test sysconfig]# service docker restart

三、结果测试

[root@Test sysconfig]# docker push 192.168.1.100:5000/hello-test:latest

[root@Test sysconfig]# docker push 192.168.1.100:5000/hello-test:latest
 
The push refers to repository [192.168.1.100:5000/hello-test]
 
e07ee1baac5f: Mounted from hello
 
latest: digest:
 
sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4 size: 525

[root@Test sysconfig]# curl 192.168.1.100:5000/v2/_catalog

[root@Test sysconfig]# curl 192.168.1.100:5000/v2/_catalog
 
{"repositories":["hello","hello-test"]}

如果你想了解更多内容,欢迎访问我的CSDN博客:blog.csdn.net/myself88129 这里分享了许多技术文章和心得,让我们一起学习,共同进步。期待你的到来!