docker ๋ช…๋ น์–ด ๋ชจ์Œ

์“ธ ๋•Œ๋งˆ๋‹ค ๊นŒ๋จน์–ด์„œ ์‹ค๋ฌด์—์„œ ์ž์ฃผ ์“ฐ๋Š” ๋ช…๋ น์–ด ์œ„์ฃผ๋กœ ํ•œ ๋ฒˆ ์ •๋ฆฌํ•ด๋ณด์•˜๋‹ค.

๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ๋กœ๊ทธ์ธ

๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ์ฃผ์†Œ๋ฅผ ๋„˜๊ฒจ์ฃผ์ง€ ์•Š์œผ๋ฉด ๊ธฐ๋ณธ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์ธ Docker Hub์— ๋กœ๊ทธ์ธ๋œ๋‹ค.

docker login
# Authenticating with existing credentials...
# Login Succeeded

# Logging in with your password grants your terminal complete access to your account.
# For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/

[-u | --username]๊ณผ [-p | --password] ์˜ต์…˜์„ ์ฃผ๋ฉด ๋ฐ”๋กœ ๋กœ๊ทธ์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

docker login -u coodingpenguin -p **** my-registry.com

๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ์ฃผ์†Œ๋ฅผ ์ธ์ž๋กœ ๋„˜๊ฒจ์ฃผ๋ฉด ๋น„๊ณต๊ฐœ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์— ๋กœ๊ทธ์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

docker login my-registry.com

๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ๋กœ๊ทธ์•„์›ƒ

๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ์ฃผ์†Œ๋ฅผ ์ธ์ž๋กœ ๋„˜๊ฒจ์ฃผ๋ฉด ํ•ด๋‹น ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์—์„œ ๋กœ๊ทธ์•„์›ƒ๋œ๋‹ค. ๋„˜๊ฒจ์ฃผ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ๊ธฐ๋ณธ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์ธ Docker Hub์—์„œ ๋กœ๊ทธ์•„์›ƒ๋œ๋‹ค.

docker logout
# Removing login credentials for https://index.docker.io/v1/

์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰

docker search ubuntu
# NAME                             DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
# ubuntu                           Ubuntu is a Debian-based Linux operating sysโ€ฆ   15952     [OK]
# websphere-liberty                WebSphere Liberty multi-architecture images โ€ฆ   294       [OK]
# open-liberty                     Open Liberty multi-architecture images basedโ€ฆ   59        [OK]

[-f | --filter]๋ฅผ ์‚ฌ์šฉํ•ด ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ํ•„ํ„ฐ๋งํ•  ์ˆ˜ ์žˆ๋‹ค. ํ˜„์žฌ ์ง€์›๋˜๋Š” ํ•„ํ„ฐ๋ง์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

  • stars(int): ์ด๋ฏธ์ง€์˜ ์Šคํƒ€ ์ˆ˜
  • is-automated(boolean): ์ด๋ฏธ์ง€ ์ž๋™ ๋นŒ๋“œ ์—ฌ๋ถ€
  • is-official(boolean): Docker Hub์—์„œ ์ธ์ฆํ•œ ๊ณต์‹ ์ด๋ฏธ์ง€ ์—ฌ๋ถ€
docker search --filter stars=100 ubuntu
# NAME                DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
# ubuntu              Ubuntu is a Debian-based Linux operating sysโ€ฆ   15952     [OK]
# websphere-liberty   WebSphere Liberty multi-architecture images โ€ฆ   294       [OK]
# ubuntu-upstart      DEPRECATED, as is Upstart (find other procesโ€ฆ   114       [OK]

--no-trunc ์˜ต์…˜์„ ์ฃผ๋ฉด ์ž˜๋ฆฐ DESCRIPTION์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

# NAME                             DESCRIPTION                                                                                            STARS     OFFICIAL   AUTOMATED
# ubuntu                           Ubuntu is a Debian-based Linux operating system based on free software.                                15952     [OK]
# websphere-liberty                WebSphere Liberty multi-architecture images based on Ubuntu 18.04                                      294       [OK]
# open-liberty                     Open Liberty multi-architecture images based on Ubuntu 18.04                                           59        [OK]

์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ

ํƒœ๊ทธ๋ฅผ ๋ช…์‹œํ•˜์ง€ ์•Š์œผ๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ latest ํƒœ๊ทธ์˜ ์ด๋ฏธ์ง€๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.

docker pull ubuntu  # ubuntu:latest
# Using default tag: latest
# latest: Pulling from library/ubuntu
# 79d0ea7dc1a8: Pull complete
# Digest: sha256:dfd64a3b4296d8c9b62aa3309984f8620b98d87e47492599ee20739e8eb54fbf
# Status: Downloaded newer image for ubuntu:latest
# docker.io/library/ubuntu:latest

ํŠน์ • ํƒœ๊ทธ์˜ ์ด๋ฏธ์ง€๊ฐ€ ํ•„์š”ํ•˜๋ฉด ๊ผญ ๋ช…์‹œํ•ด์ฃผ์ž.

docker pull ubuntu:18.04
# 18.04: Pulling from library/ubuntu
# 13f679bb266a: Pull complete
# Digest: sha256:8aa9c2798215f99544d1ce7439ea9c3a6dfd82de607da1cec3a8a2fae005931b
# Status: Downloaded newer image for ubuntu:18.04
# docker.io/library/ubuntu:18.04

๋กœ์ปฌ ์ด๋ฏธ์ง€ ์กฐํšŒ

docker images
# REPOSITORY                         TAG       IMAGE ID       CREATED             SIZE
# coodingpenguin/welcome-to-docker   v0.0.0    aaca33068baf   About an hour ago   237MB
# welcome-to-docker                  latest    aaca33068baf   About an hour ago   237MB
# ubuntu                             latest    3f5ef9003cef   2 weeks ago         69.2MB
# coodingpenguin/ubuntu              v0.0.0    3f5ef9003cef   2 weeks ago         69.2MB
# coodingpenguin/welcome-to-docker   latest    b1eb53af308a   3 weeks ago         13.6MB
# docker/welcome-to-docker           latest    b1eb53af308a   3 weeks ago         13.6MB
# ubuntu                             18.04     c1adc1968c7b   2 months ago        56.7MB

ํŠน์ • ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ ์ด๋ฏธ์ง€๋„ ์กฐํšŒ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ํƒœ๊ทธ๊นŒ์ง€ ์ผ์น˜ํ•˜๋Š” ์กฐํšŒ๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

docker images ubuntu
# REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
# ubuntu       latest    3f5ef9003cef   2 weeks ago    69.2MB
# ubuntu       18.04     c1adc1968c7b   2 months ago   56.7MB

docker images ubuntu:latest
# REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
# ubuntu       latest    3f5ef9003cef   2 weeks ago   69.2MB

docker search์—์„œ ์ œ๊ณต๋œ ํ•„ํ„ฐ ์˜ต์…˜์ฒ˜๋Ÿผ ํ•„ํ„ฐ๋ฅผ ์ง€์›ํ•˜๊ณ  ์žˆ๋‹ค. (์ž์„ธํ•œ ๋‚ด์šฉ์€ ์—ฌ๊ธฐ๋ฅผ ์ฐธ๊ณ !)
์˜ˆ๋ฅผ ๋“ค์–ด, dangling=true๋ฅผ ์ฃผ๋ฉด ํƒœ๊ทธ๊ฐ€ ์—†๋Š” ์ž„์‹œ ์ด๋ฏธ์ง€๋ฅผ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

์ด๋ฏธ์ง€ ์‚ญ์ œ

์ด๋ฏธ์ง€ ์ด๋ฆ„ + ํƒœ๊ทธ์˜ ์กฐํ•ฉ ํ˜น์€ ์ด๋ฏธ์ง€ ID๋กœ ํŠน์ • ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œํ•  ์ˆ˜ ์žˆ๋‹ค.

docker rmi ubuntu         # ํƒœ๊ทธ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ latest ํƒœ๊ทธ๋ฅผ ๊ฐ€์ง„ ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œ
docker rmi ubuntu:20.04   # ํƒœ๊ทธ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ํ•ด๋‹น ํƒœ๊ทธ์˜ ์ด๋ฏธ์ง€๋ฅผ ์‚ญ์ œ
docker rmi 3048ba078595   # ์ด๋ฏธ์ง€ ID๋กœ๋„ ์‚ญ์ œ ๊ฐ€๋Šฅ

๋ฉ”๋ชจ๋ฆฌ๋งŒ ์ฐจ์ง€ ํ•˜๋Š” ๋Œ•๊ธ€๋ง ์ด๋ฏธ์ง€๋ฅผ ํ•œ ๋ฒˆ์— ์‚ญ์ œํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, docker prune์„ ์‚ฌ์šฉํ•˜์ž.

๐Ÿ’ก ๋Œ•๊ธ€๋ง ์ด๋ฏธ์ง€(Dangling Image)๊ฐ€ ๋ฌด์—‡์ธ๊ฐ€?

๋Œ•๊ธ€๋ง ์ด๋ฏธ์ง€๋ž€ ์ด๋ฆ„์ด ์—†๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋งํ•˜๋ฉฐ, ๋นŒ๋“œํ•˜๋Š” ๊ณผ์ •์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ ๋ถ€์‚ฐ๋ฌผ์ฒ˜๋Ÿผ ์ƒ์„ฑ๋œ๋‹ค. ๋Œ•๊ธ€๋ง ์ด๋ฏธ์ง€๊ฐ€ ๋‚จ์•„ ์žˆ์œผ๋ฉด ๊ณต๊ฐ„์„ ์ฐจ์ง€ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ณดํ†ต ์ฃผ๊ธฐ์ ์œผ๋กœ ์‚ญ์ œํ•ด์ค€๋‹ค.

docker image prune
# WARNING! This will remove all dangling images.
# Are you sure you want to continue? [y/N] y
# Total reclaimed space: 0B

๋” ๋‚˜์•„๊ฐ€ ์ปจํ…Œ์ด๋„ˆ์—์„œ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€๊นŒ์ง€ ์‚ญ์ œํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด [-a | --all] ์˜ต์…˜์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

docker image prune -a
# WARNING! This will remove all images without at least one container associated to them.
# Are you sure you want to continue? [y/N] y
# Total reclaimed space: 0B

์ด๋ฏธ์ง€ ๋นŒ๋“œ

์ด๋ฏธ์ง€ ์—…๋กœ๋“œ

์šฐ์„  ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ธฐ ์ „์— ํƒœ๊น…์„ ํ•ด์•ผ ํ•œ๋‹ค. ์•„๋‹ˆ๋ฉด Permission Denied๊ฐ€ ๋œ๋‹ค..

docker tag ubuntu coodingpenguin/ubuntu:v0.0.0
# docker images
# REPOSITORY                         TAG       IMAGE ID       CREATED             SIZE
# coodingpenguin/ubuntu              v0.0.0    3f5ef9003cef   2 weeks ago         69.2MB
# ubuntu                             18.04     c1adc1968c7b   2 months ago        56.7MB

๊ทธ ๋‹ค์Œ์— ํƒœ๊น…๋œ ์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•ด์ค€๋‹ค.

docker push coodingpenguin/ubuntu:v0.0.0
# The push refers to repository [docker.io/coodingpenguin/ubuntu]
# b49483f6a0e6: Mounted from library/ubuntu
# v0.0.0: digest: sha256:9b85f48f0298ec89dcbc46b35edf9b12e5b9b04ca9cc9ea063968933ddba6adf size: 529

์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰

์ปจํ…Œ์ด๋„ˆ ์ค‘๋‹จ

์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ์ ‘์†

์‹คํ–‰ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ์กฐํšŒ

์ฐธ๊ณ  ์ž๋ฃŒ