인프런 워밍업 클럽 4기 DevOps 미션 5.
6개월 전
Docker와 Containerd 명령 실습 :
https://cafe.naver.com/kubeops/137
[root@cicd-server ~]# mkdir test
[root@cicd-server ~]# ls
anaconda-ks.cfg gradle-7.6.1-bin.zip original-ks.cfg test
[root@cicd-server ~]# cd test
[root@cicd-server test]# ls
[root@cicd-server test]# curl -O https://raw.githubusercontent.com/k8s-1pro/install/main/ground/etc/docker/Dockerfile
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 60 100 60 0 0 155 0 --:--:-- --:--:-- --:--:-- 155
[root@cicd-server test]# curl -O https://raw.githubusercontent.com/k8s-1pro/install/main/ground/etc/docker/hello.js
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 178 100 178 0 0 497 0 --:--:-- --:--:-- --:--:-- 497
[root@cicd-server test]# ls
Dockerfile hello.js
도커 허브 username : chano01794
### 빌드
[root@cicd-server test]# docker build -t chano01794/hello:1.0.0 .
[+] Building 22.1s (7/7) FINISHED docker:default
=> [internal] load .dockerignore 0.2s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from Dockerfile 0.2s
=> => transferring dockerfile: 157B 0.1s
=> [internal] load metadata for docker.io/library/node:slim 2.7s
=> [internal] load build context 0.1s
=> => transferring context: 275B 0.1s
=> [1/2] FROM docker.io/library/node:slim@sha256:b30c143a092c7dced8e17ad67a8783c03234d4844ee84c39090c9780491aaf89 17.6s
=> => resolve docker.io/library/node:slim@sha256:b30c143a092c7dced8e17ad67a8783c03234d4844ee84c39090c9780491aaf89 0.1s
=> => sha256:26c0b956ed16dae9780bcb6c24f8161b3f8d44339c435691372d8fe1f270d97b 6.57kB / 6.57kB 0.0s
=> => sha256:dad67da3f26bce15939543965e09c4059533b025f707aad72ed3d3f3a09c66f8 28.23MB / 28.23MB 2.1s
=> => sha256:b30c143a092c7dced8e17ad67a8783c03234d4844ee84c39090c9780491aaf89 5.20kB / 5.20kB 0.0s
=> => sha256:1a6a7b2e2e2c80a6973f57aa8b0c6ad67a961ddbc5ef326c448e133f93564ff9 1.93kB / 1.93kB 0.0s
=> => sha256:ea9602600a53af802a015c3d6bc5298ce2b6dff888a6f93b2861465f710804c2 3.31kB / 3.31kB 0.8s
=> => sha256:e03b89ff903664199350b286d7985167de4c079a4ed44baefc09cc1d2e0395ca 51.04MB / 51.04MB 3.7s
=> => sha256:b03d7a90d937df6cc4c0c2e094b722156a78951c3b5cbe9c383f9a735ea3c316 1.71MB / 1.71MB 1.5s
=> => sha256:748509dbfbee9fa52f4b018cdaefbc837ee275e458fbdd76b96b312b764a27ac 447B / 447B 2.2s
=> => extracting sha256:dad67da3f26bce15939543965e09c4059533b025f707aad72ed3d3f3a09c66f8 9.0s
=> => extracting sha256:ea9602600a53af802a015c3d6bc5298ce2b6dff888a6f93b2861465f710804c2 0.0s
=> => extracting sha256:e03b89ff903664199350b286d7985167de4c079a4ed44baefc09cc1d2e0395ca 3.2s
=> => extracting sha256:b03d7a90d937df6cc4c0c2e094b722156a78951c3b5cbe9c383f9a735ea3c316 0.3s
=> => extracting sha256:748509dbfbee9fa52f4b018cdaefbc837ee275e458fbdd76b96b312b764a27ac 0.0s
=> [2/2] COPY hello.js . 1.0s
=> exporting to image 0.2s
=> => exporting layers 0.1s
=> => writing image sha256:5965305dbb8602727958bac3dd598f0a55551d0e595c002dad0d07b58c1bdb49 0.0s
=> => naming to docker.io/chano01794/hello:1.0.0 0.0s
### 이미지 리스트 조회
[root@cicd-server test]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
chano01794/hello 1.0.0 5965305dbb86 21 seconds ago 230MB
chano01794/api-tester v1.0.0 529e022f4e15 2 hours ago 490MB
### 태그 변경
[root@cicd-server test]# docker tag chano01794/hello:1.0.0 chano01794/hello:2.0.0
[root@cicd-server test]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
chano01794/hello 1.0.0 5965305dbb86 45 seconds ago 230MB
chano01794/hello 2.0.0 5965305dbb86 45 seconds ago 230MB
chano01794/api-tester v1.0.0 529e022f4e15 2 hours ago 490MB
### 로그인
[root@cicd-server test]# docker login -u chano01794
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
### 이미지 업로드
[root@cicd-server test]# docker push chano01794/hello:1.0.0
The push refers to repository [docker.io/chano01794/hello]
98ca109d077d: Pushed
8a45580a6679: Mounted from library/node
d5b49e0b6f8f: Mounted from library/node
eaf814c4be3d: Mounted from library/node
59cd39de7802: Mounted from library/node
7fb72a7d1a8e: Mounted from library/node
### 이미지 삭제
[root@cicd-server test]# docker rmi chano01794/hello:1.0.0
Untagged: chano01794/hello:1.0.0
[root@cicd-server test]# docker rmi chano01794/hello:2.0.0
Untagged: chano01794/hello:2.0.0
Untagged: chano01794/hello@sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332
Deleted: sha256:5965305dbb8602727958bac3dd598f0a55551d0e595c002dad0d07b58c1bdb49
### 이미지 다운로드
[root@cicd-server test]# docker pull chano01794/hello:1.0.0
1.0.0: Pulling from chano01794/hello
dad67da3f26b: Already exists
ea9602600a53: Already exists
e03b89ff9036: Already exists
b03d7a90d937: Already exists
748509dbfbee: Already exists
88b642bb1537: Already exists
Digest: sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332
Status: Downloaded newer image for chano01794/hello:1.0.0
docker.io/chano01794/hello:1.0.0
### 이미지 -> 파일로 변환
[root@cicd-server test]# docker save -o file.tar chano01794/hello:1.0.0
[root@cicd-server test]# ls file.tar
file.tar
[root@cicd-server test]# ls
Dockerfile file.tar hello.js
### 파일 -> 이미지로 변환
[root@cicd-server test]# docker load -i file.tar
Loaded image: chano01794/hello:1.0.0
[root@cicd-server test]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
chano01794/hello 1.0.0 5965305dbb86 3 minutes ago 230MB
chano01794/api-tester v1.0.0 529e022f4e15 2 hours ago 490MB
### 정리
[root@cicd-server test]# docker rmi chano01794/hello:1.0.0
Untagged: chano01794/hello:1.0.0
Untagged: chano01794/hello@sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332
Deleted: sha256:5965305dbb8602727958bac3dd598f0a55551d0e595c002dad0d07b58c1bdb49
[root@cicd-server test]#
[root@cicd-server test]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
chano01794/api-tester v1.0.0 529e022f4e15 2 hours ago 490MB
컨테이너디
### 네임스페이스 조회
[root@k8s-master ~]# ctr ns list
NAME LABELS
k8s.io
### 특정 네임스페이스 내 이미지 조회
ctr -n k8s.io image list
# 너무 많이 나오는데..?
### 다운로드 및 이미지 확인 (이미지는 default라는 네임스페이스에 다운 받아집니다.)
[root@k8s-master ~]# ctr images pull docker.io/chano01794/hello:1.0.0
docker.io/chano01794/hello:1.0.0: resolved |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:88b642bb153727bb4c187997177696815efcd9d0a0fe0b5757bc2f9c6cad1a3f: done |++++++++++++++++++++++++++++++++++++++|
config-sha256:5965305dbb8602727958bac3dd598f0a55551d0e595c002dad0d07b58c1bdb49: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:dad67da3f26bce15939543965e09c4059533b025f707aad72ed3d3f3a09c66f8: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:ea9602600a53af802a015c3d6bc5298ce2b6dff888a6f93b2861465f710804c2: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:e03b89ff903664199350b286d7985167de4c079a4ed44baefc09cc1d2e0395ca: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:b03d7a90d937df6cc4c0c2e094b722156a78951c3b5cbe9c383f9a735ea3c316: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:748509dbfbee9fa52f4b018cdaefbc837ee275e458fbdd76b96b312b764a27ac: done |++++++++++++++++++++++++++++++++++++++|
elapsed: 8.0 s total: 77.2 M (9.7 MiB/s)
unpacking linux/amd64 sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332...
done: 7.472278898s
[root@k8s-master ~]# ctr ns list
NAME LABELS
default
k8s.io
[root@k8s-master ~]# ctr images list
REF TYPE DIGEST SIZE PLATFORMS LABELS
docker.io/chano01794/hello:1.0.0 application/vnd.docker.distribution.manifest.v2+json sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332 77.2 MiB linux/amd64 -
### 태그 변경
[root@k8s-master ~]# ctr images tag docker.io/chano01794/hello:1.0.0 docker.io/chano01794/hello:2.0.0
docker.io/chano01794/hello:2.0.0
[root@k8s-master ~]# ctr images list
REF TYPE DIGEST SIZE PLATFORMS LABELS
docker.io/chano01794/hello:1.0.0 application/vnd.docker.distribution.manifest.v2+json sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332 77.2 MiB linux/amd64 -
docker.io/chano01794/hello:2.0.0 application/vnd.docker.distribution.manifest.v2+json sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332 77.2 MiB linux/amd64 -
### 업로드
[root@k8s-master ~]# ctr image push docker.io/chano01794/hello:2.0.0 --user chano01794
Password:
manifest-sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332: done |++++++++++++++++++++++++++++++++++++++|
config-sha256:5965305dbb8602727958bac3dd598f0a55551d0e595c002dad0d07b58c1bdb49: done |++++++++++++++++++++++++++++++++++++++|
elapsed: 3.1 s total: 8.9 Ki (2.9 KiB/s)
### 이미지 (namespace : default) -> 파일로 변환
[root@k8s-master ~]# ctr -n default image export file.tar docker.io/chano01794/hello:1.0.0
[root@k8s-master ~]# ls
anaconda-ks.cfg file.tar k8s-local-volume monitoring original-ks.cfg
### 파일 -> 이미지로 변환 (namespace : k8s.io)
[root@k8s-master ~]# ctr -n k8s.io image import file.tar
unpacking docker.io/chano01794/hello:1.0.0 (sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332)...done
[root@k8s-master ~]# ctr -n k8s.io image list | grep hello
docker.io/chano01794/hello:1.0.0 application/vnd.docker.distribution.manifest.v2+json sha256:7aa9b5ce123a7edc1cbebcd0b85360b3a2b38c8cc71a0ee43036673136858332 77.2 MiB linux/amd64 io.cri-containerd.image=managed
### 삭제 (namespace : k8s.io)
[root@k8s-master ~]# ctr -n k8s.io image remove docker.io/chano01794/hello:1.0.0
docker.io/chano01794/hello:1.0.0
[root@k8s-master ~]# ctr -n k8s.io image list | grep hello
Docker 이미지 사이즈 :
https://cafe.naver.com/kubeops/158
### [미션5] Docker vs Containerd 이미지 사이즈 차이 비교 실습
### [STEP 1] Docker로 이미지 다운로드 및 사이즈 확인 (cicd-server에서 실행)
# 목적: Docker가 실제 어떤 이미지 크기를 보여주는지 확인
[root@cicd-server test2]# docker pull 1pro/api-tester:latest
latest: Pulling from 1pro/api-tester
38a980f2cc8a: Already exists
de849f1cfbe6: Already exists
a7203ca35e75: Already exists
f3eeefdc54d7: Pull complete
4f4fb700ef54: Pull complete
Digest: sha256:189625384d2f2856399f77b6212b6cfc503931e8b325fc1388e23c8a69f3f221
Status: Downloaded newer image for 1pro/api-tester:latest
docker.io/1pro/api-tester:latest
[root@cicd-server test2]#
[root@cicd-server test2]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
1pro/api-tester latest 08a0bfca3fbb 19 months ago 490MB
# SIZE 약 490MB
### [STEP 2] Containerd로 이미지 다운로드 및 사이즈 확인 (k8s-master에서 실행)
# 목적: Containerd는 동일한 이미지를 몇 MB로 보여주는지 확인
[root@k8s-master test2]# ctr image pull docker.io/1pro/api-tester:latest
docker.io/1pro/api-tester:latest: resolved |++++++++++++++++++++++++++++++++++++++|
index-sha256:189625384d2f2856399f77b6212b6cfc503931e8b325fc1388e23c8a69f3f221: done |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:da882e44367891d885b4557726ea8ffa1a6eaa8fe03ce85e1fb55a19dbf55978: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1: done |++++++++++++++++++++++++++++++++++++++|
config-sha256:08a0bfca3fbb866e63ea5b601d44877ff76fbe3b054b4e0af06494501d5b0eb3: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:38a980f2cc8accf69c23deae6743d42a87eb34a54f02396f3fcfd7c2d06e2c5b: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:de849f1cfbe60b1c06a1db83a3129ab0ea397c4852b98e3e4300b12ee57ba111: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:a7203ca35e75e068651c9907d659adc721dba823441b78639fde66fc988f042f: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:f3eeefdc54d7d01fa080d4edf5f1ddd080b446a1633ed1b619faff8159f4b083: done |++++++++++++++++++++++++++++++++++++++|
elapsed: 3.7 s total: 2.8 Ki (771.0 B/s)
unpacking linux/amd64 sha256:189625384d2f2856399f77b6212b6cfc503931e8b325fc1388e23c8a69f3f221...
done: 12.67536041s
[root@k8s-master test2]# ctr image list | grep api-tester
docker.io/1pro/api-tester:latest application/vnd.oci.image.index.v1+json sha256:189625384d2f2856399f77b6212b6cfc503931e8b325fc1388e23c8a69f3f221 248.3 MiB linux/amd64,linux/arm64,unknown/unknown -
# SIZE 약 248.3 MiB
### [STEP 3] Docker 이미지 저장 → 파일 (cicd-server에서 실행)
# 목적: 동일한 이미지를 파일로 저장했을 때 사이즈 확인
[root@cicd-server test2]# docker save -o docker-image.tar 1pro/api-tester:latest
[root@cicd-server test2]# ls -lh docker-image.tar
-rw-------. 1 root root 472M Jun 17 16:50 docker-image.tar
# -> 약 472MB
### [STEP 4] 파일 전송 → 배포 서버로 (cicd-server에서 실행)
[root@cicd-server test2]# scp docker-image.tar root@192.168.56.30:/root
root@192.168.56.30's password:
docker-image.tar 100% 472MB 34.0MB/s 00:13
### [STEP 5] Containerd에서 기존 이미지 삭제 후 import (k8s-master에서 실행)
# 목적: Docker에서 만든 tar 파일을 Containerd로 import 해보며 사이즈 변화 체크
[root@k8s-master test2]# ctr image rm docker.io/1pro/api-tester:latest
docker.io/1pro/api-tester:latest
[root@k8s-master test2]# cd ..
[root@k8s-master ~]# ls
anaconda-ks.cfg docker-image.tar file.tar k8s-local-volume monitoring original-ks.cfg test2
[root@k8s-master ~]# ctr image import docker-image.tar
unpacking docker.io/1pro/api-tester:latest (sha256:ce5b6c9e3b93096e8813c99528af58fd2603bb7e46e8023f131acab303e55836)...done
[root@k8s-master ~]# ctr image list | grep api-tester
docker.io/1pro/api-tester:latest application/vnd.docker.distribution.manifest.v2+json sha256:ce5b6c9e3b93096e8813c99528af58fd2603bb7e46e8023f131acab303e55836 471.5 MiB linux/amd64 -
# -> 결과: 약 471.5 MiB
# ** scp 로 ~에 보내서 기존에 다른 폴더 만든데랑 꼬여서 중간에 cd.. 넣었...
### [STEP 6] Containerd에서 다시 다운로드 후 파일로 저장 (k8s-master에서 실행)
# 목적: Containerd가 다운로드한 이미지를 파일로 export 해보고 크기 비교
[root@k8s-master ~]# ctr image rm docker.io/1pro/api-tester:latest
docker.io/1pro/api-tester:latest
[root@k8s-master ~]# ctr image pull docker.io/1pro/api-tester:latest
docker.io/1pro/api-tester:latest: resolved |++++++++++++++++++++++++++++++++++++++|
index-sha256:189625384d2f2856399f77b6212b6cfc503931e8b325fc1388e23c8a69f3f221: done |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:da882e44367891d885b4557726ea8ffa1a6eaa8fe03ce85e1fb55a19dbf55978: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1: done |++++++++++++++++++++++++++++++++++++++|
config-sha256:08a0bfca3fbb866e63ea5b601d44877ff76fbe3b054b4e0af06494501d5b0eb3: exists |++++++++++++++++++++++++++++++++++++++|
layer-sha256:38a980f2cc8accf69c23deae6743d42a87eb34a54f02396f3fcfd7c2d06e2c5b: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:de849f1cfbe60b1c06a1db83a3129ab0ea397c4852b98e3e4300b12ee57ba111: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:a7203ca35e75e068651c9907d659adc721dba823441b78639fde66fc988f042f: done |++++++++++++++++++++++++++++++++++++++|
layer-sha256:f3eeefdc54d7d01fa080d4edf5f1ddd080b446a1633ed1b619faff8159f4b083: done |++++++++++++++++++++++++++++++++++++++|
elapsed: 3.7 s total: 2.8 Ki (772.0 B/s)
unpacking linux/amd64 sha256:189625384d2f2856399f77b6212b6cfc503931e8b325fc1388e23c8a69f3f221...
done: 25.828317ms
[root@k8s-master ~]# ctr image export containerd-image.tar docker.io/1pro/api-tester:latest
[root@k8s-master ~]# ls -lh containerd-image.tar
-rw-r--r--. 1 root root 249M Jun 17 17:02 containerd-image.tar
# -> 약 249MB
### [STEP 7] 파일 전송 → Docker 서버로 복사 (k8s-master에서 실행)
[root@k8s-master ~]# scp containerd-image.tar root@192.168.56.20:/root
The authenticity of host '192.168.56.20 (192.168.56.20)' can't be established.
ECDSA key fingerprint is SHA256:l/1SJtioqx5vZeMC7uILw/KtalAXEavCzYllT7ZWmuo.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.56.20' (ECDSA) to the list of known hosts.
root@192.168.56.20's password:
containerd-image.tar 100% 248MB 38.0MB/s 00:06
### [STEP 8] Docker에서 기존 이미지 삭제 후 containerd 이미지 import (cicd-server에서 실행)
[root@cicd-server test2]# ls
docker-image.tar
[root@cicd-server test2]# docker image rm 1pro/api-tester:latest
Untagged: 1pro/api-tester:latest
Untagged: 1pro/api-tester@sha256:189625384d2f2856399f77b6212b6cfc503931e8b325fc1388e23c8a69f3f221
Deleted: sha256:08a0bfca3fbb866e63ea5b601d44877ff76fbe3b054b4e0af06494501d5b0eb3
Deleted: sha256:e2fb66ac6dafbd5edcc5d3ff932de5fad633224097fe643b49c04dd9d56193d6
Deleted: sha256:2029a1bf55bf9a369aa169dfc17ecd7da632987259d1c8c303778b24db5f8bbd
[root@cicd-server test2]# cd ..
[root@cicd-server ~]# ls
anaconda-ks.cfg containerd-image.tar gradle-7.6.1-bin.zip original-ks.cfg test test2
[root@cicd-server ~]# docker load -i containerd-image.tar
b54d2aff45ec: Loading layer [==================================================>] 17.15MB/17.15MB
5f70bf18a086: Loading layer [==================================================>] 32B/32B
Loaded image: 1pro/api-tester:latest
[root@cicd-server ~]# docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE
chano01794/api-tester v1.0.0 529e022f4e15 4 hours ago 490MB
1pro/api-tester latest 08a0bfca3fbb 19 months ago 490MB
# -> 결과: 다시 490MB로 증가
댓글을 작성해보세요.