Pages

Saturday, August 26, 2017

Docker - Running docker registry locally

There are cases in big organizations where internet access will be restricted. In the case of docker, most of the containers will be created locally from the original Image downloaded from internet.  Most of the images that developer will be working on will downloaded from internet and modified accordingly. the modified images are then saved to the local docker registry where other teams will consume that. In this article we will see how we can create our own local docker registry to push and pull images

1. Install docker-registry rpm using yum
yum install docker-distribution

2. In order to run the docker registry specific ports needs to be opened. The docker registry runs on port 5000. Configure the firewall or iptables to enable port 5000

3. Run the docker-registry service
service docker-distribution restart

The docker-distribution configuration file is available at /etc/docker-distribution/registry/config.yml

Don't make any modification as of now and move with the existing configuration.

4. Download an image from online dockerhub repository.
docker run --name myhello hello-world
The hello-world is a minimal docker implementation.

5. Once the container image is downloaded and run. We can then make the necessary changes to the docker configuration file to change the registry location.

Make the necessary changes as below to the file /etc/sysconfig/docker. For elements we need to un comment the lines. make sure to uncomment the lines and configure the registry as below

ADD_REGISTRY='--add-registry localhost:5000'
INSECURE_REGISTRY='--insecure-registry localhost:5000'

Once the changes are done, restart the docker engine.

6. Now tag and push the hello-world image to local registry as
[root@ip-10-149-66-36 init.d]# docker tag hello-world localhost:5000/hello-me:latest

[root@ip-10-149-66-36 init.d]# docker push localhost:5000/hello-me:latest
The push refers to a repository [localhost:5000/hello-me]
45761469c965: Pushed
latest: digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f size: 524

We are pushing the hello-world image as hello-me to the local registry.Now once the image is pushed to the local registry, we can check the images with

[root@ip-10-149-66-36 init.d]# docker images
REPOSITORY                  TAG                IMAGE ID              CREATED              SIZE
docker.io/hello-world      latest              1815c82652c0        9 weeks ago         1.84 kB
localhost:5000/hello-me latest              1815c82652c0        9 weeks ago         1.84 kB

we can see that 2 hello-world images are available with docker.io and localhost:5000. Remove both the images so that we can download the images again from our local registry

[root@ip-10-149-66-36 init.d]# docker pull hello-me
Using default tag: latest
Trying to pull repository localhost:5000/hello-me ...
latest: Pulling from localhost:5000/hello-me

Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f

Once the "docker pull hello-me" command ran we can see that docker is using hello-me to obtain from the local registry. once pull is done we can run the "docker images" and see that the image is available locally

This is how we can run a local docker registry to push and pull images.

No comments :

Post a Comment