이번 포스팅은 Docker의 Image 저장소인 Registry에 대해서 알아 보겠 습니다. Docker registry는 Docker를 통해 생성하는 Image들을 저장해주는 저장소로써의 기능을 제공을 합니다.
Docker에서 지원하는 Registry의 종류에는 아래와 같은 3가지가 있습니다.
- public으로 인터넷상에서 운영되는 Docker Hub 사이트
- 기업망 내부에서 사용하는 경우
- 자신의 로컬서버에 설치해 사용할 수 있는 Private Local Registry
이런 Docker Registry를 사용하는 이유는 첫번째로 생성되는 이미지들의 위치를 통제할 수 있고, CI(Continuous Integration), CD(Continuous deployment)를 지원하는 Tool들과 파이프라인을 구성해 운영의 자동화를 가능하게 해줍니다.
우선 내 로컬 컴퓨터의 Doker의 Registry설정 정보를 보려면 아래 명령을 사용을 하면 됩니다 .
- 명령어
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/ ==> 현재 로컬 컴퓨터에서 퍼블릭 Registry로 docker site로 설정
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
root@test-VirtualBox:~# ^C
|

우선 Registry 실습에 들어가기 전에 위의 그림에서 기억해야할것은 언제 새로운 Image가 생성이 되느냐 입니다. 새로운 Image가 생성이 되는 경우는 아래와 같습니다.
- dockerfile을 이용해 신규 Image 생성시
- 기존 Image에 tag를 하면 새로운 이미지가 생성이 됩니다.
- container 실행 중 Commit 명령 실행시
그럼 이제 registory관련 명령을 살펴 보겠 습니다.
1. 로컬 컴퓨터에 registory를 구성하기 위해 Docker Hub로 부터 registory:2.5 image 다운 및 실행
- 명령어
docker run -d -p 5000:5000 --restart=always --name registry registry:2.5
-d는 registry 컨테이너를 백그라운드로 실행
-p는 호스트 컴퓨터의 사용 포트는 5000번, container port 는 5000번으로 설정
--restart=always는 Docker Daemon실행시 registry 컨테이너 자동 실행
--name registry registry:2.5는 컨테이너 Image는 registry:2.5사용 컨테이너 이름은 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:~#
|
로그에서 보듯이 이제 registry라는 컨테이너가 실행이 되었습니다.
2. 그럼 이제 테스트를 위해 docker에서 ubuntu 16.04 image 다운로드를 합니다.
- docker pull ubuntu:16.04 ==> 도커로 부터 ubuntu:16.04를 다운로드
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. 다운받은 ubuntu image를 tag명령을 통해 새로운 Image생성
- docker tag ubuntu:16.04 localhost:5000/my-ubuntu:1.0
==> ubuntu:16.04를 localhost:5000/my-ubuntu:1.0라는 이름으로 tagging
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. 생성된 Image를 Local registory로 저장.
- docker push localhost:5000/my-ubuntu:1.0
localhost:5000/my-ubuntu:1.0 image를 로컬 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. 그럼 이제 생성한 image를 삭제해 보겠 습니다.
- # docker rmi -f localhost:5000/my-ubuntu:1.0 ==> 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. 자 이제 그럼 4.에서 local registry에 저장하였던 이미지를 복사해 보겠습니다.
- docker pull localhost:5000/my-ubuntu:1.0 ==> local registry에서 my-ubuntu:1.0 이미지 복사
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
|
'도커' 카테고리의 다른 글
[클라우드] 7. Docker Volumn (2) | 2022.08.07 |
---|---|
[클라우드] 6. Dockerfile 사용하기 (0) | 2022.08.07 |
[클라우드] 4. Docker Network (7) | 2022.08.05 |
[클라우드] 3. Docker 기본 명령어 (8) | 2022.08.03 |
[클라우드]2. Docker 환경 구성 하기 (3) | 2022.08.03 |