Saturday 4 June 2022

Deploy a Docker Registry


#Run a local registry

sudo docker run -d -p 5000:5000 --restart=always --name registry registry:2

Unable to find image 'registry:2' locally

2: Pulling from library/registry

2408cc74d12b: Pull complete

ea60b727a1ce: Pull complete

c87369050336: Pull complete

e69d20d3dd20: Pull complete

fc30d7061437: Pull complete

Digest: sha256:bedef0f1d248508fe0a16d2cacea1d2e68e899b2220e2258f1b604e1f327d475

Status: Downloaded newer image for registry:2

33f98447cf29cbaafc46c7c817fd6cf69c19f140df1bc9b558269fd4a7519c63


sudo docker ps

CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS          PORTS                                       NAMES

33f98447cf29   registry:2   "/entrypoint.sh /etc…"   18 seconds ago   Up 17 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   registry


#Pull the Ubuntu image from Docker Hub

sudo docker pull ubuntu:20.04

20.04: Pulling from library/ubuntu

d5fd17ec1767: Pull complete

Digest: sha256:47f14534bda344d9fe6ffd6effb95eefe579f4be0d508b7445cf77f61a0e5724

Status: Downloaded newer image for ubuntu:20.04

docker.io/library/ubuntu:20.04


sudo docker images

REPOSITORY                 TAG       IMAGE ID       CREATED       SIZE

registry                   2         773dbf02e42e   9 days ago    24.1MB

ubuntu                     20.04     53df61775e88   5 weeks ago   72.8MB


#tag the ubuntu image

sudo docker tag ubuntu:20.04 localhost:5000/my-ubuntu


sudo docker images

REPOSITORY                 TAG       IMAGE ID       CREATED       SIZE

registry                   2         773dbf02e42e   9 days ago    24.1MB

ubuntu                     20.04     53df61775e88   5 weeks ago   72.8MB

localhost:5000/my-ubuntu   latest    53df61775e88   5 weeks ago   72.8MB


#Push the image to the local registry 

sudo docker push localhost:5000/my-ubuntu

Using default tag: latest

The push refers to repository [localhost:5000/my-ubuntu]

bf8cedc62fb3: Pushed

latest: digest: sha256:9d42d0e3e57bc067d10a75ee33bdd1a5298e95e5fc3c5d1fce98b455cb879249 size: 529


sudo docker inspect 33f98447cf29


sudo ls -l /mnt/docker-data/volumes/2a817dabc8a2d4a15ae3e41afcdc7d3e9eb83d0fa2aa574f06c21a18ee18c134/_data/docker/registry/v2/repositories/my-ubuntu/

total 12

drwxr-xr-x 3 root root 4096 Jun  4 16:53 _layers

drwxr-xr-x 4 root root 4096 Jun  4 16:53 _manifests

drwxr-xr-x 2 root root 4096 Jun  4 16:53 _uploads


#Remove the locally cached images 

sudo docker image remove ubuntu:20.04

Untagged: ubuntu:20.04

Untagged: ubuntu@sha256:47f14534bda344d9fe6ffd6effb95eefe579f4be0d508b7445cf77f61a0e5724


sudo docker image remove localhost:5000/my-ubuntu

Untagged: localhost:5000/my-ubuntu:latest

Untagged: localhost:5000/my-ubuntu@sha256:9d42d0e3e57bc067d10a75ee33bdd1a5298e95e5fc3c5d1fce98b455cb879249

Deleted: sha256:53df61775e8856a464ca52d4cd9eabbf4eb3ceedbde5afecc57e417e7b7155d5

Deleted: sha256:bf8cedc62fb3ef98ad0dff2be56ca451dd3ea69abd0031ad3e0fe5d9f9e4dfff


sudo docker images

REPOSITORY   TAG       IMAGE ID       CREATED      SIZE

registry     2         773dbf02e42e   9 days ago   24.1MB


#Pull the localhost:5000/my-ubuntu image from the local registry

sudo docker pull localhost:5000/my-ubuntu

Using default tag: latest

latest: Pulling from my-ubuntu

d5fd17ec1767: Pull complete

Digest: sha256:9d42d0e3e57bc067d10a75ee33bdd1a5298e95e5fc3c5d1fce98b455cb879249

Status: Downloaded newer image for localhost:5000/my-ubuntu:latest

localhost:5000/my-ubuntu:latest


#To stop the registry

sudo docker container stop registry

registry


sudo docker ps

CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES


#To remove the container

sudo docker container rm -v registry

registry


docs.docker.com

No comments:

Post a Comment