Skip to content

Deploy Local Docker Registry Server

Configure Docker Local Registry

A Docker registry is a centralized repository for storing and distributing Docker images. It serves as a storage location for Docker images, which are the packaged and portable units used to create containers. It enables users to share and access container image with ease.

Docker hub is the default public registry provided by docker, where we can find different collection of pre-built images. We can also set up our own private registry or cloud-based solutions like AWS Elastic Container Registry (ECR), Google Container Registry (GCR) etc.

In this post we are going to deploy Local docker registry server on our own environment with below requirements.

requirements:

registry name: swan-local-DockerReg

port number : 5000

start type: Automatic

Registry Storage Path: /opt/registryData

Table of Contents

Deploy Local Docker Registry Server

Create Private Docker Registry with docker run.

  1. Create a directory for docker registry.

# mkdir /opt/registryData

2. start docker registry with below command

# sudo docker run -d -p 5000:5000 –restart=always –name swan-local-DockerReg \
-v /opt/registryData:/var/lib/registry registry:2

deploy a Local docker registry server

3. check docker registry container

# docker ps

copy and image from docker hub to local registry

  1. Pull nginx latest image from Docker hub

# docker pull nginx

2.Tag the image as localhost:5000/my-nginx. This will create additional tag for the nginx image. When Pushing Docker interprets the first part of the tag is a hostname and port this as the location of a registry

#docker tag nginx localhost:5000/my-nginx-image

deploy a Local docker registry server

3. Push the image to our local registry running at localhost:5000. This image will push to our created directory /opt/registryData

#docker push localhost:5000/my-nginx-image

4. Remove the locally-cached nginx and localhost:5000/my-nginx images, for test pulling the image from local registry. Below commands does not remove the localhost:5000/my-nginx-image from your registry.

#docker rmi -f nginx

#docker rmi -f localhost:5000/my-nginx-image

5. Pull the localhost:5000/my-nginx-image image from your local registry.

#docker pull localhost:5000/my-nginx-image

Stop a Local Registry

  1. to stop a local registry

#docker stop <container id>

#docker stop 1b5c1f9012d4

Conclusion

In this article we have seen how to configure a local docker registry and push and pull image from it. To learn more about docker, visit official Docker Website

Also read: Docker installation, Docker Commands