Running your own private docker registry service

I’m talking about a service like docker hub for your organization. This can be achieved by using docker’s registry image. I assume that you have docker running on your host.Let’s dive deep into its implementation.

Pull the registry image from docker hub

docker pull registry

Docker’s private registry image serves on port 5000. So we will forward to port 5000 on host.

docker run -d -p 5000:5000 –name dilipregistry registry

Lets pull an image locally and then push it to your docker registry

docker pull ubuntu

Tag the image like <registry_server_ip>:<port>/<name_of_image>

 docker tag ubuntu localhost:5000/ubuntu

push it to your docker registry

 docker push localhost:5000/ubuntu

You can search for the image which you just pushed to private registry.

 docker images localhost:5000

docker stop registry && docker rm -v registry

By default, your registry container uses a docker volume on the host filesystem.

Specifically, you might want to point your volume location to a specific place in order to more easily access your registry data. To do so you can:

docker run -d -p 5000:5000 –restart=always –name registry \
-v `pwd`/data:/var/lib/registry \
registry:2

For wider adoption of your docker private registry over the network you need to give TLS certs to docker daemon.

creating self-signed TLS certificates 

mkdir -p certs

openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key -x509 -days 365 -out certs/domain.crt

Make sure you stopped your registry from the previous steps, then start your registry again with TLS enabled:

 docker run -d -p 5000:5000 –restart=always –name registry \
-v `pwd`/certs:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
registry:2

You should now be able to access your registry from another docker host:

 docker pull ubuntu
docker tag ubuntu <registry_server_ip>:5000/ubuntu
docker push <resistry_server_ip>:5000/ubuntu
docker pull <registry_server_ip>:5000/ubuntu

Reference: docker documentation

Feel free to comment and always open for advises.

 

Advertisements

Author: Dilip Renkila

A Cloud enthusiast.

1 thought on “Running your own private docker registry service”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s