Private docker registry and python

Viewed 846

I'm failing to use a private docker registry from python. It seems like the environment configurations are not read.

Main steps and error

In /etc/docker/registries.yaml I defined the private registry as

mirrors:
  "192.168.2.62:5055":
    endpoint:
      - "http://192.168.2.62:5055"

However, when I execute

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'])

I get there error message

Get https://192.168.2.62:5055/v2/: http: server gave HTTP response to HTTPS client

for reproducing the example:

(you need edit the IP to your local machine IP)

I started the private registry within a docker container using docker-compose

version: '3'
services:
   registry:
     image: registry:2
     ports:
     - 192.168.2.62:5055:5000

next I defined the docker file

%%writefile /tmp/docker_test/Dockerfile

FROM alpine:3.7
CMD ["echo","HELLO WORLD"]

and build it from within python using

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)
1 Answers

The registries.yaml is the configuration for the registry from Kubernetes. Especially k3s. For reconfiguring a local docker it is required to reconfigure /etc/docker/daemon.json and add the following line

{ "insecure-registries":["localhost:5055","192.168.2.62:5055"] }
Related