๐Ÿ“‚ Container & K8S/Docker

[Docker] ๋„์ปค ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์™€ ๋„์ปค ํ—ˆ๋ธŒ

dhyuck 2021. 9. 22. 17:32
๋ฐ˜์‘ํ˜•

๋„์ปค ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ๋Š” ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•˜๊ณ  ๋ฐฐํฌ ํ•  ์ˆ˜ ์žˆ๋Š” ์„œ๋ฒ„ ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ, ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•˜๊ณ  ๋ฐฐํฌํ•˜๋Š” ํ‘œ์ค€ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.
๋„์ปค ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ๋Š” Apache ๋ผ์ด์„ผ์Šค๋ฅผ ๋”ฐ๋ฅด๋Š” ์˜คํ”ˆ์†Œ์Šค์ž…๋‹ˆ๋‹ค.

๋„์ปค ํ—ˆ๋ธŒ๋Š” ๋„์ปค ์‚ฌ์—์„œ ํ˜ธ์ŠคํŒ…ํ•˜๋Š” ๋„์ปค ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์ด๋ฉฐ, ๋„์ปค์—์„œ ๊ธฐ๋ณธ์œผ๋กœ ์ฐธ์กฐํ•ฉ๋‹ˆ๋‹ค.

  • ๋„์ปค ํ—ˆ๋ธŒ ๊ณ„์ • ๋กœ๊ทธ์ธ / ๋กœ๊ทธ์•„์›ƒ

      docker login
      docker logout
  • ๋„์ปค ํ—ˆ๋ธŒ๋กœ ์ด๋ฏธ์ง€ Push / Pull

      docker image push {๊ณ„์ •๋ช…}/{์ €์žฅ์†Œ๋ช…}:[ํƒœ๊ทธ ์ด๋ฆ„]
      docker image pull {๊ณ„์ •๋ช…}/{์ €์žฅ์†Œ๋ช…}:[ํƒœ๊ทธ ์ด๋ฆ„]
    
      # ex) ๋„์ปค ํ—ˆ๋ธŒ "hyuckang" ๊ณ„์ •์˜ "test_ubuntu" ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— "1.0" ํƒœ๊ทธ๋กœ push/pull
      docker image push hyuckang/test_ubuntu:1.0
      docker image pull hyuckang/test_ubuntu:1.0
    
      # ์œ„์˜ ๋ช…๋ น๊ณผ ๋™์ผํ•˜๋‹ค
      docker image push docker.io/hyuckang/test_ubuntu:1.0
      docker image pull docker.io/hyuckang/test_ubuntu:1.0
  • ๋„์ปค ๋กœ์ปฌ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ์‹คํ–‰

    ๋กœ์ปฌ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ๋Š” ๋„์ปค์—์„œ ์ œ๊ณตํ•˜๋Š” ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ ์ด๋ฏธ์ง€๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ตฌ๋™ํ•˜์—ฌ ๊ตฌ์ถ•ํ•ฉ๋‹ˆ๋‹ค.

      docker container run -d -p 5005:5000 --restart=always --name my_registry registry:2
      # --restart always์˜ ๊ฒฝ์šฐ ๋„์ปค ์—”์ง„์ด ์žฌ์‹œ์ž‘๋˜๋Š” ๊ฒฝ์šฐ ์ž๋™์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์žฌ์‹œ์ž‘ํ•˜๋„๋ก ํ•˜๋Š” ์˜ต์…˜์ž…๋‹ˆ๋‹ค.
  • ๋„์ปค ๋กœ์ปฌ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ๋กœ ์ด๋ฏธ์ง€ Push / Pull

    ๋กœ์ปฌ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์— ์ด๋ฏธ์ง€๋ฅผ Push / Pull ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ• ๊นŒ?

    ๊ธฐ๋ณธ์ ์œผ๋กœ ๋„์ปค ํ—ˆ๋ธŒ๊ฐ€ ๊ธฐ๋ณธ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฏธ์ง€ ํƒœ๊ทธ์—์„œdocker.io๊ฐ€ ์ƒ๋žต ๋˜์–ด์žˆ๋‹ค.

    (docker pull ubuntu ๋Š” docker pull docker.io/library/ubuntu ์˜ ๋‹จ์ถ•ํ‚ค์ด๋‹ค)

    ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๋กœ์ปฌ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ๋กœ ์ฐพ์•„์„œ ์ด๋ฏธ์ง€ ํƒœ๊ทธ๋ฅผ Push/Pullํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ด๋ฏธ์ง€ ํƒœ๊ทธ์— ๋„๋ฉ”์ธ์ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.

    (docker pull myregistrydomain:port/foo/bar ๋ช…๋ น์€ myregistry:port์— ์žˆ๋Š” ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์—์„œ foo/bar ์ด๋ฏธ์ง€๋ฅผ ์ฐพ๋Š” ๋ช…๋ น์ž…๋‹ˆ๋‹ค.)

      docker image push {๋„๋ฉ”์ธ๋ช…}/{์ด๋ฏธ์ง€๋ช…}
      docker image pull {๋„๋ฉ”์ธ๋ช…}/{์ด๋ฏธ์ง€๋ช…}
    
      # ex) 
      docker image push localhost:5005/hyuckang_base:1.0
      docker iamge pull localhost:5005/hyuckang_base:1.0
    
      docker image push localhost:5005/hyuckang/test_ubuntu:1.0
      docker image push localhost:5005/hyuckang/test_ubuntu:1.1
  • ๋„์ปค ๋กœ์ปฌ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ์ด๋ฏธ์ง€ ํ™•์ธํ•˜๊ธฐ

      http://<ip/hostname>:<port>/v2/_catalog
    
      # ex)
      curl http://localhost:5005/v2/_catalog
  • ๋„์ปค ๋กœ์ปฌ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ์ด๋ฏธ์ง€์˜ ํƒœ๊ทธ ํ™•์ธํ•˜๊ธฐ

      http://<ip/hostname>:<port>/v2/<์ด๋ฏธ์ง€๋ช…>/tags/list
    
      # ex)
      curl http://localhost:5005/v2/hyuckang/test_ubuntu/tags/list
      curl http://localhost:5005/v2/hyuckang_base/tags/list

๋ฐ˜์‘ํ˜•