dockergitlab-cidocker-registrydocker-containerdocker-in-docker

How to push a docker image to a local registry from job container?


I'm using docker executor with DinD in Gitlab CI, and I have a local registry container running in the host machine.

I want to push an image that is being built in the job container to the local registry container running in the host machine.

Normally what would you do if pushing from the host computer is pushing to the localhost at the port of the registry container. Like this:

docker push localhost:5000/my-ubuntu

but since I'm pushing from the job container I don't know how to do this.

I tried with the host computer ip:

docker push some_ip_address:5000/my-ubuntu

but I got:

The push refers to repository [some_ip_address:5000/my-ubuntu]
Get "https://some_ip_address:5000/v2/": http: server gave HTTP response to HTTPS client

and the job failed...


Solution

  • As you can see from the error whne you use the coputer ip you are actually getting a response from the docker registry.

    The problem is that docker by default expects registries to use secure HTTPS but your local registry uses plain HTTP. In order for you to be able to connect to an HTTP registry you have to add it to the insecure-registries in your daemon.json:

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

    This will need to be done in the container that wants to push the image (not the docker host).