Search code examples
dockersslregistrydocker-registry

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.


Solution

  • 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.