Setting up private registry for docker images

The registry is a stateless and highly scalable server-side open source application permissive under Apache license, which let you store your images privately and makes internal distribution and management easy. In case you don't want private registry docker hub is the best place to store your images.

To configure own private registry follow below steps:


1. To start the registry container, which will be used as local registry on the docker host:

[root@localhost ~]# docker run -d -p 5000:5000 --restart=always --name registry -v /local_registry/images:/var/lib/registry registry:2
Unable to find image 'registry:2' locally
2: Pulling from library/registry
c87736221ed0: Pull complete
1cc8e0bb44df: Pull complete
54d33bcb37f5: Pull complete
e8afc091c171: Pull complete
b4541f6d3db6: Pull complete
Digest: sha256:77a8fb00c00b99568772a70f0863f6192ff2635e4af4e22e4d9c622edeb5f2de
Status: Downloaded newer image for registry:2
97f0845f8c3a0064ef0144aba57610e4c4f3d79947eed734d045f4d65b33a754


NOTE: In '-v /local_registry/images:/var/lib/registry' switch "/local_registry/images" is a folder on the host which will be used to store images and will be bind to "/var/lib/registry" container folder.


[root@localhost ~]# docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
97f0845f8c3a        registry:2          "/entrypoint.sh /etc…"   15 seconds ago      Up 13 seconds       0.0.0.0:5000->5000/tcp   registry


2. Pull any image from Docker public registry [Optional, as i don't have any other image for this demo]:

[root@localhost ~]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
e7c96db7181b: Pull complete
Digest: sha256:769fddc7cc2f0a1c35abb2f91432e8beecf83916c421420e6a6da9f8975464b6
Status: Downloaded newer image for alpine:latest


3. Tag image within local registry with new name:


[root@localhost ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              055936d39205        13 days ago         5.53MB
nginx               latest              53f3fd8007f7        2 weeks ago         109MB
registry            2                   f32a97de94e1        2 months ago        25.8MB


[root@localhost ~]# docker tag alpine:latest localhost:5000/my-alpine-latest


[root@localhost ~]# docker image ls
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
alpine                            latest              055936d39205        13 days ago         5.53MB
localhost:5000/my-alpine-latest   latest              055936d39205        13 days ago         5.53MB
nginx                             latest              53f3fd8007f7        2 weeks ago         109MB
registry                          2                   f32a97de94e1        2 months ago        25.8MB


4. Push newly tagged image to local registry:

[root@localhost ~]# docker push localhost:5000/my-alpine-latest
The push refers to repository [localhost:5000/my-alpine-latest]
f1b5933fe4b5: Pushed
latest: digest: sha256:bf1684a6e3676389ec861c602e97f27b03f14178e5bc3f70dce198f9f160cce9 size: 528


[root@localhost ~]# docker image ls
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
alpine                            latest              055936d39205        13 days ago         5.53MB
localhost:5000/my-alpine-latest   latest              055936d39205        13 days ago         5.53MB
nginx                             latest              53f3fd8007f7        2 weeks ago         109MB
registry                          2                   f32a97de94e1        2 months ago        25.8MB


5. [OPTIONAL] you can delete images downloaded from Docker public registry and the tagged one.

[root@localhost ~]# docker image rm alpine:latest
Untagged: alpine:latest
Untagged: alpine@sha256:769fddc7cc2f0a1c35abb2f91432e8beecf83916c421420e6a6da9f8975464b6


[root@localhost ~]# docker image rm localhost:5000/my-alpine-latest
Untagged: localhost:5000/my-alpine-latest:latest
Untagged: localhost:5000/my-alpine-latest@sha256:bf1684a6e3676389ec861c602e97f27b03f14178e5bc3f70dce198f9f160cce9
Deleted: sha256:055936d3920576da37aa9bc460d70c5f212028bda1c08c0879aedf03d7a66ea1
Deleted: sha256:f1b5933fe4b5f49bbe8258745cf396afe07e625bdab3168e364daf7c956b6b81


6. To pull locally pushed image:

[root@localhost ~]# docker pull localhost:5000/my-alpine-latest
Using default tag: latest
latest: Pulling from my-alpine-latest
e7c96db7181b: Pull complete
Digest: sha256:bf1684a6e3676389ec861c602e97f27b03f14178e5bc3f70dce198f9f160cce9
Status: Downloaded newer image for localhost:5000/my-alpine-latest:latest


If you notice, this pushed image will get store to below path:

/local_registry/images/docker/registry/v2/repositories/my-alpine-latest

Comments

Post a Comment

Popular posts from this blog

Recover or restore initramfs file in RHEL or CentOS 7

Space reclamation / UNMAP on RHEL or CentOS 7

How to recover /boot partition on RHEL or CentOS 7?