Installation

To have the Docker / Kubernetes images that will be created during the Lab, among several excellent repositories, I preferred the official Docker one, it is simple and light, with more resources, perhaps I would use Jfrog, Gitlab also has a Registry, but it is based exactly on this Docker one, so I opt for the simplest one now.

registry – Official Image | Docker Hub

The image is based on alpine, so it’s very small.

I’ll create a docker and assign an IP 172.21.5.76, in DNS as registry.devops-db.local.

An important point is to map the container’s /var/lib/registry folder to a Host folder or a Docker Volume, so there’s no problem of having to recreate the container and losing the images.

(docker-compose.yaml)

version: "3"

services:
  srv-registry-01:
    container_name: srv-registry-01
    image: registry:2
    environment:
      - REGISTRY_STORAGE_DELETE_ENABLED=true
    ports:
      - "5000:5000/tcp"
      - "5000:5000/udp"
    volumes:
      - /work/registry:/var/lib/registry
    restart: unless-stopped
    networks:
      - registry_bridge
networks:
  registry_bridge:
    name: registry_bridge
    driver: bridge

With docker compose, all you have to do is create the container:

$ docker-compose up -d
Creating network "registry_bridge" with driver "bridge"
Creating srv-registry-01 ... done

$ docker container ls -a
CONTAINER ID   IMAGE                                   COMMAND                  CREATED          STATUS                    PORTS                                                                                  NAMES
5cb3e3200141   registry:2                              "/entrypoint.sh /etc…"   53 seconds ago   Up 52 seconds             0.0.0.0:5000->5000/tcp, 0.0.0.0:5000->5000/udp, :::5000->5000/tcp, :::5000->5000/udp   srv-registry-01

New DNS entry responding:

Tests

To test this, use another host with Docker:

Do a pull of any image, in the example, that of Ubuntu:

$ docker image pull ubuntu:22.04
22.04: Pulling from library/ubuntu
Digest: sha256:77906da86b60585ce12215807090eb327e7386c8fafb5402369e421f44eff17e
Status: Downloaded newer image for ubuntu:22.04
docker.io/library/ubuntu:22.04

Assign the tag with the address:registry container port:

$ docker image tag ubuntu:22.04 registry.devops-db.internal:5000/ubuntu:22.04

Push the image to the Registry:

$ docker image push registry.devops-db.internal:5000/ubuntu:22.04
The push refers to repository [registry.devops-db.internal:5000/ubuntu]
a510ae0f066c: Pushed
22.04: digest: sha256:6bb9faf5914e1c3ffcace129df01d3894635eccb3c4e452a4d0d83919dea246a size: 529

It may be that when pushing the image, docker returns the error:

Error response from daemon: Get "https://registry.devops-db.internal:5000/v2/": http: server gave HTTP response to HTTPS client

This means that because it is not https, the destination (registry) is “untrustworthy”, in this case, it is necessary to add an exception in Docker.

sudo vi /etc/docker/daemon.json

add:
{
  "insecure-registries":["172.21.5.76:5000","registry.devops-db.internal:5000","registry.lab.devops-db.info:5000"]
}

At this point the Registry already has the image stored and ready to use.

There is an “API” provided by the Registry, Example:

http://registry.devops-db.internal:5000/v2/_catalog

{"repositories":["ubuntu"]}

http://registry.devops-db.internal:5000/v2/ubuntu/tags/list

{"name":"ubuntu","tags":["22.04"]}

To check whether the images can be used, remove them locally:

$ docker image rmi registry.devops-db.internal:5000/ubuntu:22.04
Untagged: registry.devops-db.internal:5000/ubuntu:22.04
Untagged: registry.devops-db.internal:5000/ubuntu@sha256:6bb9faf5914e1c3ffcace129df01d3894635eccb3c4e452a4d0d83919dea246a

$ docker image rmi ubuntu:22.04
Untagged: ubuntu:22.04
Untagged: ubuntu@sha256:77906da86b60585ce12215807090eb327e7386c8fafb5402369e421f44eff17e

Check:

$ docker image ls '*ubuntu*'
REPOSITORY                                TAG       IMAGE ID       CREATED       SIZE

$ docker image ls '*/ubuntu*'
REPOSITORY                                TAG       IMAGE ID       CREATED       SIZE

Now pull the image from the local Registry:

$ docker image pull registry.devops-db.internal:5000/ubuntu:22.04

docker image ls '*/ubuntu*'
REPOSITORY                                TAG       IMAGE ID       CREATED       SIZE
registry.devops-db.internal:5000/ubuntu   22.04     52882761a72a   4 weeks ago   77.9MB

Image ready, test with a container:

$ docker run -ti --rm registry.devops-db.internal:5000/ubuntu:22.04
root@18f7701b070d:/#

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.