Sachith Muhandiram
Sachith Muhandiram

Reputation: 2972

Docker local registry tries to push images to docker.io

I have created a local docker registry. Steps I have followed. Creating certificate files.

mkdir -p /etc/docker/certs.d/123.456.78.9:5000

cp domain.crt /etc/docker/certs.d/123.456.78.9:5000/ca.crt

cp domain.crt /usr/local/share/ca-certificates/ca.crt

update-ca-certificates

Installed Docker registry, as given in official guide

docker run -d -p 5000:5000 --restart=always --name registry -v $PWD/certs:/certs -e REGISTRY_HTTP_ADDR=0.0.0.0:443 -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key registry:2

Pulling and pushing Docker images :

docker pull ubuntu:16.04

docker tag ubuntu:16.04 mydocker_registry/my_ubuntu

docker push mydocker_registry/my-ubuntu

My image push tries to access docker.io, so error is obvious.

The push refers to repository [docker.io/mydocker_registry/my_ubuntu]
03901b4a2ea8: Preparing  
denied: requested access to the resource is denied

My /etc/hosts file looks like this

123.456.78.9 mydocker_registry

Here I feel I have missed some small step. I can not figure that out. Thanks in advance.

Upvotes: 1

Views: 4991

Answers (3)

Sachith Muhandiram
Sachith Muhandiram

Reputation: 2972

Ok, after days of reading and trying, I have fixed my problem thanks to the helps given by /r/docker redditters :-)

Please note that this is working for your local domain only

Creating certificate files for your domain.

Here my domain is registry.myregistry.com.

openssl req -newkey rsa:4096 -nodes -sha256 -keyout registry.myregistry.com.key -x509 -days 365 -out registry.myregistry.com.crt

mkdir -p /etc/docker/certs.d/registry.myregistry.com:443

Copy certificates files to appropriate locations.

cp registry.myregistry.com.crt /etc/docker/certs.d/registry.myregistry.com:443/ca.crt

cp registry.myregistry.com /usr/local/share/ca-certificates/ca.crt

update-ca-certificates

Docker registry initialization

docker run -d -p 443:443 --restart=always --name registry -v $PWD/certs:/certs -e REGISTRY_HTTP_ADDR=0.0.0.0:443 -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.myregistry.com.crt -e REGISTRY_HTTP_TLS_KEY=/certs/registry.myregistry.com.key registry:2

Pulling and Pushing docker images to registry

docker pull alpine:latest

docker tag alpine:latest registry.myregistry.com:443/myalpine

docker push registry.myregistry.com:443/myalpine

No errors, its pushing successfully.

To be done is, accepting pull requests from other users in the same network.

Upvotes: 0

Adiii
Adiii

Reputation: 60046

you need to add you your registry url in the tag, if the local registry URL is not part of your Docker image tag, by default it will push to official docker registry.

So that is why you are seeing in the push log

The push refers to a repository [docker.io/mydocker_registry/my_ubuntu]

so All you add to add the full path of your docker registry.

docker tag ubuntu:16.04 123.456.78.9:5000/mydocker_registry/my_ubuntu
docker push 123.456.78.9:5000/mydocker_registry/my_ubuntu 

Here 123.456.78.9 refer to your local registry. if it is localhost then just 123.456.78.9 this with localhost

You can verify the registry access in browser if it is accessiable you will able to push.

https://myregistry.com/v2/_catalog
or 
http://localhost:5000/v2/_catalog

Upvotes: 3

Wesgur
Wesgur

Reputation: 3237

Try adding your registry as insecure registries.

If you are using Linux, edit your daemon.json under /etc/docker

Add

{
  "insecure-registries" : ["registry-ip:registry-port"]
}

And run in terminal

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

Upvotes: 3

Related Questions