Docker

[Cloud] 5. Docker Registry

트리스탄1234 2023. 5. 26. 11:47
728x90
반응형

In this post, we will learn about Docker's image Registry. Docker registry provides a function as a repository to store images created through Docker. ​ There are three types of registry supported by Docker as follows.

- A Docker Hub site that is publicly operated on the Internet

- When used inside the corporate network

- Private Local Registry that can be installed and used on your local server

The reason for using this Docker Registry is that you can control the location of the images that are created first, and configure tools and pipelines that support CI (Continuous Integration) and CD (Continuous deployment) to enable automation of operations.

First of all, you can use the following command to view the registry setting information of Docker on your local computer.

- command

docker info

root@test-VirtualBox:~# docker info
Client:
Context: default
Debug Mode: false
Server:
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 4
Server Version: 20.10.12
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version:
runc version:
init version:
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.15.0-41-generic
Operating System: Ubuntu 20.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.834GiB
Name: test-VirtualBox
ID: WLRT:FIRY:GPWN:2DSM:ZWM5:42WQ:BQOU:WRXC:QYAW:7X5J:WHGY:DDDM
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/ ==>Currently set up as a docker site on your local machine as a public
registry
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
root@test-VirtualBox:~# ^C

First of all, before entering the registry exercise, the thing to remember in the above picture is when a new image is created.

The case where a new image is created is as follows.

- When creating a new image using dockerfile

- If you tag an existing image, a new image is created.

- When executing Commit command while container is running

Now, let's take a look at the registory-related commands.

1. Download and run registory:2.5 image from Docker Hub to configure registory on local machine

- command

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

-d runs the registry container in the background

-p sets the host computer's port to 5000 and container port to 5000.

--restart=always automatically run the registry container when running Docker Daemon

--name registry registry:2.5 is the container Image uses registry:2.5

the container name is registry

 

root@test-VirtualBox:~# docker run -d -p 5000:5000 --restart=always --name registry registry:2.5
Unable to find image 'registry:2.5' locally
2.5: Pulling from library/registry
c1e54eec4b57: Pull complete
606cf3574ddf: Pull complete
9776f61d75c4: Pull complete
602df3b64569: Pull complete
0cb17236f8e2: Pull complete
Digest: sha256:1a741bd1ad954fe4d7109cfdeabdf65f72c9b51b198f41f67ca1f86582bbbca8
Status: Downloaded newer image for registry:2.5
169120cef0ca68302e8a3803c1864c3d11b98954d8089ba0aba3a984c2dd4f65
root@test-VirtualBox:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
169120cef0ca registry:2.5 "/entrypoint.sh /etc…" 18 minutes ago Up 18 minutes 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp registry
root@test-VirtualBox:~#

As you can see from the log, the container named registry is now running. 2. Now, for testing, download ubuntu 16.04 image from docker. - docker pull ubuntu:16.04 ==> download ubuntu:16.04 from docker

root@test-VirtualBox:~# docker pull ubuntu:16.04
16.04: Pulling from library/ubuntu
58690f9b18fc: Pull complete
b51569e7c507: Pull complete
da8ef40b9eca: Pull complete
fb15d46c38dc: Pull complete
Digest: sha256:20858ebbc96215d6c3c574f781133ebffdc7c18d98af4f294cc4c04871a6fe61
Status: Downloaded newer image for ubuntu:16.04
docker.io/library/ubuntu:16.04
root@test-VirtualBox:~#

3. Create a new image using the tag command for the downloaded ubuntu image

- docker tag ubuntu:16.04 localhost:5000/my-ubuntu:1.0

==> tagging ubuntu:16.04 as localhost:5000/my-ubuntu:1.0

root@test-VirtualBox:~# docker tag ubuntu:16.04 localhost:5000/my-ubuntu:1.0
root@test-VirtualBox:~#
root@test-VirtualBox:~#
root@test-VirtualBox:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 16.04 b6f507652425 10 months ago 135MB
localhost:5000/my-ubuntu 1.0 b6f507652425 10 months ago 135MB
registry 2.5 bae2e2e45eb1 3 years ago 37.8MB
root@test-VirtualBox:~#

4. Save the created image as a local registry.

- docker push localhost:5000/my-ubuntu:1.0

==> copy localhost:5000/my-ubuntu:1.0 image to local registory

root@test-VirtualBox:~# docker push localhost:5000/my-ubuntu:1.0
The push refers to repository [localhost:5000/my-ubuntu]
1251204ef8fc: Pushed
47ef83afae74: Pushed
df54c846128d: Pushed
be96a3f634de: Pushed
1.0: digest: sha256:a3785f78ab8547ae2710c89e627783cfa7ee7824d3468cae6835c9f4eae23ff7 size: 1150

5. Now, let's delete the created image.

- # docker rmi -f localhost:5000/my-ubuntu:1.0 ==> Delete the image created with tag

root@test-VirtualBox:~# docker rmi -f localhost:5000/my-ubuntu:1.0
Untagged: localhost:5000/my-ubuntu:1.0
Untagged: localhost:5000/my-ubuntu@sha256:a3785f78ab8547ae2710c89e627783cfa7ee7824d3468cae6835c9f4eae23ff7
root@test-VirtualBox:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 16.04 b6f507652425 10 months ago 135MB
registry 2.5 bae2e2e45eb1 3 years ago 37.8MB

6. Now, let's copy the image saved in the local registry in step 4.

- docker pull localhost:5000/my-ubuntu:1.0 ==> copy my-ubuntu:1.0 image from local registry

root@test-VirtualBox:~# docker pull localhost:5000/my-ubuntu:1.0
1.0: Pulling from my-ubuntu
Digest: sha256:a3785f78ab8547ae2710c89e627783cfa7ee7824d3468cae6835c9f4eae23ff7
Status: Downloaded newer image for localhost:5000/my-ubuntu:1.0
localhost:5000/my-ubuntu:1.0
root@test-VirtualBox:~#
root@test-VirtualBox:~#
root@test-VirtualBox:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 16.04 b6f507652425 10 months ago 135MB
localhost:5000/my-ubuntu 1.0 b6f507652425 10 months ago 135MB
registry 2.5 bae2e2e45eb1 3 years ago 37.8MB

 

 
 
"이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다."

728x90
반응형

'Docker' 카테고리의 다른 글

[Cloud] 6. Using Dockerfile  (67) 2023.05.31
[Cloud] 4. Docker Network  (89) 2023.05.28
[Cloud] 3. Docker Basic Commands  (43) 2023.05.23
[Cloud]2. Configuring your Docker environment  (69) 2023.05.20
[Cloud] 1. Docker Overview  (65) 2023.05.18