我用python的私有docker注册表失败了。好像环境配置没有被读取。
主要步骤和错误
在 /etc/docker/registries.yaml
我将私人注册处定义为
mirrors:
"192.168.2.62:5055":
endpoint:
- "http://192.168.2.62:5055"
但是,当我执行
import docker
client = docker.from_env()
image_tag = "192.168.2.62:5055/dockertest:latest"
for line in client.images.push(repository=image_tag, stream=True, decode=True):
if 'error' in line and line['error']:
print(line['error'])
我得到的错误信息是
Get https://192.168.2.62:5055/v2/: http: server gave HTTP response to HTTPS client
用于复制 的例子。
(你需要编辑IP到你的本地机器IP)
我在一个docker容器中使用docker-compose启动了私有注册表。
version: '3'
services:
registry:
image: registry:2
ports:
- 192.168.2.62:5055:5000
接下来我定义了docker文件
%%writefile /tmp/docker_test/Dockerfile
FROM alpine:3.7
CMD ["echo","HELLO WORLD"]
并在python中使用
import docker
client = docker.from_env()
image, logs = client.images.build(dockerfile = "Dockerfile",
path = "/tmp/docker_test",
tag = "192.168.2.62:5055/dockertest")
print(image)
print(logs)
for l in logs:
print(l)
的 registries.yaml
是来自Kubernetes的注册表的配置。尤其是 k3s
. 对于重新配置本地docker,它需要重新配置。/etc/docker/daemon.json
并添加以下一行
{ "insecure-registries":["localhost:5055","192.168.2.62:5055"] }