我没有使用来自 python 的私有(private) docker 注册表。似乎没有读取环境配置。
主要步骤和错误
在 /etc/docker/registries.yaml
我将私有(private)注册表定义为
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-compose 在 docker 容器中启动了私有(private)注册表
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"] }
关于docker - 私有(private) docker 注册表和 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62318875/