docker-library / docker

Docker Official Image packaging for Docker
Apache License 2.0
1.09k stars 568 forks source link

docker:cli how to set insecure-registries? #490

Closed hgfi closed 2 months ago

hgfi commented 2 months ago

Hi,

I'm using a docker:cli image inside kubernetes with a buildkit pod to run my CI pipelines. The build part works great but when I try to login into a local insecure registry to push my images it complains : http: server gave HTTP response to HTTPS client

Usually I would just configure /etc/docker/daemon.json but I can't do that because there is no daemon in the cli image.

So how would I go about pushing images to an insecure registry?

tianon commented 2 months ago

That's a daemon configuration, so it has to be set on whichever daemon your CLI is talking to in order for it to take effect.

hgfi commented 2 months ago

I have no docker daemon running, only builkitd inside another pod. I create a remote builder inside the docker:cli pod.

docker buildx create --name remote-builder --driver remote tcp://buildkitd:1234 no daemon needed then I use it to build docker build --builder remote-builder -t <my_registry>/path/image_name:tag --push no daemon needed, no error for insecure registry, only 401 because I'm not logged in.

When I try to docker login it complains about the insecure registry. So do I really need a running daemon to login into my registry?

hgfi commented 2 months ago

Okay so I managed to do it, inside buildkitd.toml I configured the insecure registry, then inside my pipeline instead of docker login I write the .docker/config.json file by hand.

mkdir ~/.docker
echo "{\"auths\":{\"$REGISTRY_URL\":{\"auth\":\"$(echo -n ${REGISTRY_LOGIN}:${REGISTRY_PASSWORD} | base64)\"}}}" > ~/.docker/config.json

Then I can call docker build <...> --push and everything works just fine.