๐Ÿณ Docker again

yeeun leeยท2020๋…„ 7์›” 8์ผ
0

ํ•ด๋‹น ๊ฒŒ์‹œ๋ฌผ์€ ๊ณต๋ถ€๋ฅผ ๋ชฉ์ ์œผ๋กœ ์ •๋ฆฌํ–ˆ์œผ๋ฉฐ, ์•„๋ž˜ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ–ˆ๋‹ค. ์•„๋ฌด๋ฆฌ ์ฝ์–ด๋„ ์ง์ ‘ ๋ฐฐํฌํ•ด๋ณด์ง€ ์•Š๋Š” ์ด์ƒ 100% ์™€๋‹ฟ์ง€๋Š” ์•Š์„ ๊ฒƒ ๊ฐ™์ง€๋งŒ, ์ตœ๋Œ€ํ•œ ์ง€์‹์„ ๋ชจ์•„๋ชจ์•„ ์ •๋ฆฌํ•˜๋ ค๊ณ  ๋…ธ๋ ฅํ–ˆ๋‹ค.

opensoure.com
์ดˆ๋ณด๋ฅผ ์œ„ํ•œ ๋„์ปค ์•ˆ๋‚ด์„œ ์‹œ๋ฆฌ์ฆˆ
๋„์ปค ๊ณต์‹ ๋ฌธ์„œ
Docker์™€ ECR, ECS ๊ฒฝํ—˜
์™œ ๊ตณ์ด ๋„์ปค(์ปจํ…Œ์ด๋„ˆ)๋ฅผ ์จ์•ผ ํ•˜๋‚˜์š”?

1. ๊ธฐ๋ณธ ๊ฐœ๋…

Docker

  • ๋„์ปค๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค๊ณ , ๋ฐฐํฌํ•˜๊ณ , ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์„ ์‰ฝ๊ฒŒ ๋งŒ๋“ค์–ด์ฃผ๋Š” open source tool์ด๋‹ค.
  • ๋„์ปค๋Š” ๊ฐ€์ƒ ๋จธ์‹ virtual machine๊ณผ ๋น„์Šทํ•˜์ง€๋งŒ, ๊ฐ€์ƒ์˜ ์šด์˜ ํ™˜๊ฒฝvirtual operating system์„ ๋งŒ๋“œ๋Š” ๊ฐœ๋…๊ณผ ๋” ๊ฐ€๊น๋‹ค.
  • ํ˜„์žฌ ๋„์ปค๋Š” go์–ธ์–ด๋กœ ๊ฐœ๋ฐœ๋˜๊ณ  ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค ๐Ÿค”

๋Œ€์ฒด ์™œ ํ•„์š”ํ• ๊นŒ?

๊ฐœ๋ฐœ์ž์™€ ์‹œ์Šคํ…œ ์šด์˜์ž(system operators) ๋ชจ๋‘์—๊ฒŒ ๋„์›€์ด ๋œ๋‹ค. ๊ฐœ๋ฐœ์ž๋“ค์€ ์ฝ”๋“œ๊ฐ€ ์–ด๋–ค ์‹œ์Šคํ…œ์—์„œ ๋Œ์•„๊ฐˆ์ง€์— ๋Œ€ํ•œ ๊ฑฑ์ •์€ ํ•˜์ง€ ์•Š๊ณ  ์ฝ”๋“œ ์ž‘์„ฑ์—๋งŒ ์ง‘์ค‘ํ•  ์ˆ˜ ์žˆ๊ณ , ์šด์˜์ž ์ž…์žฅ์—์„œ๋Š” ๋„์ปค๊ฐ€ ์‹œ์Šคํ…œ์˜ ์ˆ˜๋ฅผ ์ž ์žฌ์ ์œผ๋กœ ์ค„์—ฌ์ฃผ๊ณ , ์œ ์—ฐ์„ฑ์„ ์ค„ ์ˆ˜ ์žˆ๊ธฐ์— ํฐ ์žฅ์ ์„ ์ง€๋‹Œ๋‹ค.

๋„์ปค๋ฅผ ์ฒ˜์Œ ์จ๋ณด์‹  ๋ถ„์˜ ๋ธ”๋กœ๊ทธ๋ฅผ ๋ณด๋‹ˆ ๋ฐฐํฌ ํžˆ์Šคํ† ๋ฆฌ๋ฅผ ๋‚จ๊ธธ ์ˆ˜ ์žˆ๊ณ , ๋กค๋ฐฑ์ด ์‰ฌ์›Œ์„œ ์ข‹์•˜๋‹ค๊ณ  ํ•œ๋‹ค. ๊ฐ™์€ ์„œ๋ฒ„๋ฅผ ๋Œ๋ฆฌ๋ ค๊ณ  ํ•  ๋•Œ ์„œ๋กœ ๋‹ค๋ฅธ ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ๋ฒ„์ „, ์˜์กด์„ฑ ๋ฌธ์ œ๋กœ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฐ ๋ฌธ์ œ๋ฅผ ์—†์• ์ค„ ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด ์ปจํ…Œ์ด๋„ˆ ๊ฐœ๋…์ด๋‹ค.

- ํ•˜์ดํผ๋ฐ”์ด์ €?

ํ˜ธ์ŠคํŠธ ์ปดํ“จํ„ฐ์—์„œ ๋‹ค์ˆ˜์˜ ์šด์˜ ์ฒด์ œ๋ฅผ ๋™์‹œ์— ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ๋…ผ๋ฆฌ์  ํ”Œ๋žซํผ์„ ๋งํ•œ๋‹ค. ๊ฐ€์ƒํ™” ๋จธ์‹  ๋ชจ๋‹ˆํ„ฐ ๋˜๋Š” ๊ฐ€์ƒํ™” ๋จธ์‹  ๋งค๋‹ˆ์ €๋ผ๊ณ ๋„ ๋ถ€๋ฅธ๋‹ค. ์‰ฝ๊ฒŒ ๋งํ•ด์„œ ํ•˜์ดํผ๋ฐ”์ด์ € ๋•๋ถ„์— ๋งฅ๋ถ์—์„œ ์œˆ๋„์šฐ๋ž‘ ๋ฆฌ๋ˆ…์Šค๋ฅผ ์“ธ ์ˆ˜ ์žˆ๋Š”๊ฑฐ๋‹ค.

Container

  • ์ปจํ…Œ์ด๋„ˆ๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ณผ ๊ด€๋ จ๋œ ๋ชจ๋“  ๊ฒƒ๋“ค(๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ์˜์กด์„ฑ ๋“ฑ)์„ ํŒจํ‚ค์ง•ํ•ด ํ•˜๋‚˜๋กœ์„œ ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค€๋‹ค.
  • ์ปจํ…Œ์ด๋„ˆ ๋•์— ์ฝ”๋“œ๋ฅผ ์“ฐ๊ณ  ํ…Œ์ŠคํŠธํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๊ธฐ๊ธฐ๊ฐ€ ์–ด๋–ค customized๋œ ์„ธํŒ…์„ ๊ฐ–๊ณ  ์žˆ๋Š”์ง€ ์ƒ๊ด€ ์—†์ด ์–ด๋–ค ๋ฆฌ๋ˆ…์Šค ๋จธ์‹ ์—์„œ๋„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์ž‘๋™ํ•  ์ˆ˜ ์žˆ๋‹ค.

- dependency(์˜์กด์„ฑ)

์ฝ”๋“œ์—์„œ ๋‘ ๋ชจ๋“ˆ ๊ฐ„์˜ ์—ฐ๊ฒฐ, ๊ฐ์ฒด ์ง€ํ–ฅ ์–ธ์–ด์—์„œ๋Š” ๋‘ ํด๋ž˜์Šค ๊ฐ„์˜ ๊ด€๊ณ„๋ผ๊ณ ๋„ ํ•œ๋‹ค. ํ•˜๋‚˜์˜ ๋ชจ๋“ˆ์ด ๋ฐ”๋€Œ๋ฉด ์˜์กดํ•œ ๋‹ค๋ฅธ ๋ชจ๋“ˆ๊นŒ์ง€ ๋ณ€๊ฒฝ์ด ์ด๋ฃจ์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์— ์œ„ํ—˜ํ•˜๋‹ค.

image

  • ์ด๋ฏธ์ง€๋Š” ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰์— ํ•„์š”ํ•œ ํŒŒ์ผ๊ณผ ์„ค์ •๊ฐ’๋“ฑ์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ๊ฒƒ์œผ๋กœ, ์ƒํƒœ๊ฐ’์„ ๊ฐ€์ง€์ง€ ์•Š๊ณ  ๋ณ€ํ•˜์ง€ ์•Š๋Š”๋‹ค(Immutable).
  • ์ด๋ฏธ์ง€๋Š” ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ๋ชจ๋“  ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋ฐ›๊ณ  ์ปจํ…Œ์ด๋„ˆ๋งŒ ์ƒ์„ฑํ•˜๋ฉด ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์€ ๋ฌธ์ œ ์—†๋‹ค.
  • ์ด๋ฏธ์ง€๊ฐ€ ๋งŽ์ด ์Œ“์ด๋ฉด ์šฉ๋Ÿ‰์„ ์ฐจ์ง€ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€๋Š” ์ง€์šฐ๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.
  • ์ด๋ฏธ์ง€๋Š” url๋ฐฉ์‹์œผ๋กœ ๊ด€๋ฆฌํ•˜๊ณ , ํƒœ๊ทธ๋ฅผ ๋ถ™์ผ ์ˆ˜ ์žˆ๋‹ค. ๋„์ปค ํ—ˆ๋ธŒ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋„์ปค ์ด๋ฏธ์ง€ ์ด๋ฆ„์€ /<IMAGE_NAME>:์ด๋‹ค. ๊ธฐ๋ณธ ๋„ค์ž„ ์ŠคํŽ˜์ด์Šค๋Š” library (=๊ธฐ๋ณธ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ๋Š” ๋„์ปค ํ—ˆ๋ธŒ)๋‹ค.

- digest

๋‹ค์ด์ œ์ŠคํŠธ๋Š” ์ด๋ฏธ์ง€๋ฅผ ํ•ด์‹œํ•œ ๊ฐ’์ด๋‹ค.

A digest is the sha256 hash of a docker image, but an image is not really a single file but rather a set of layers.

Dockerfile

๋„์ปค๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด Dockerfile์ด๋ผ๋Š” ํŒŒ์ผ์— ์ž์ฒด DSL(Domain-specific language)์–ธ์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๊ณผ์ •์„ ์ ๋Š”๋‹ค. dockerfile์„ ํ†ตํ•ด image๋ฅผ buildํ•˜๊ฒŒ ๋œ๋‹ค.

  • FROM creates a layer from the ubuntu:18.04 Docker image.
  • COPY adds files from your Docker clientโ€™s current directory.
  • RUN builds your application with make.
  • CMD specifies what command to run within the container.
FROM ubuntu:18.04
COPY . /app
RUN make /app
CMD python /app/app.py

dockerfile & image & container

๋„์ปค ์ด๋ฏธ์ง€๋กœ ์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋งŒ๋“ค์–ด์ง„๋‹ค. ์ฆ‰ ์ปจํ…Œ์ด๋„ˆ๋Š” ์ด๋ฏธ์ง€๋ฅผ ์‹คํ–‰ํ•œ ์ƒํƒœ๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์ถ”๊ฐ€๋˜๊ฑฐ๋‚˜ ๋ณ€ํ•˜๋Š” ๊ฐ’์€ ์ปจํ…Œ์ด๋„ˆ์— ์ €์žฅ๋œ๋‹ค.

๊ฐ™์€ ์ด๋ฏธ์ง€์—์„œ ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๊ณ  ์ปจํ…Œ์ด๋„ˆ์˜ ์ƒํƒœ๊ฐ€ ๋ฐ”๋€Œ๊ฑฐ๋‚˜ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์‚ญ์ œ๋˜๋”๋ผ๋„ ์ด๋ฏธ์ง€๋Š” ๋ณ€ํ•˜์ง€ ์•Š๊ณ  ๊ทธ๋Œ€๋กœ ๋‚จ์•„์žˆ๋‹ค. ์ด๋Š” ๋ฐฐํฌ(ํ˜น์€ ์‹คํ–‰)์‹œ์ ๊ณผ ์ƒ๊ด€ ์—†์ด ์„œ๋ฒ„์˜ ๋‚ด์šฉ์„ ๋˜‘๊ฐ™์ด ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ฒŒ๋” ๋งŒ๋“ค์–ด์ค€๋‹ค.

๋„์ปค ํŒŒ์ผ == ์„œ๋ฒ„ ์šด์˜ ๊ธฐ๋ก
๋„์ปค ์ด๋ฏธ์ง€ == ๋„์ปค ํŒŒ์ผ + ์‹คํ–‰ ์‹œ์ 
๋„์ปค ์ปจํ…Œ์ด๋„ˆ == ๋„์ปค ์ด๋ฏธ์ง€ + ํ™˜๊ฒฝ ๋ณ€์ˆ˜

- docker hub

๋„์ปค ์ด๋ฏธ์ง€๋Š” docker hub์— ๋“ฑ๋กํ•˜๊ฑฐ๋‚˜ docker registry ์ €์žฅ์†Œ๋ฅผ ์ง์ ‘ ๋งŒ๋“ค์–ด์„œ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‚ด ๊ณ„์ •์— ๋“ค์–ด๊ฐ€๋ฉด ์ƒ์„ฑํ•œ repository์˜ tags์— image๋“ค์ด ์žˆ๋‹ค.

layer

๋„์ปค ์ด๋ฏธ์ง€๋Š” ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰์— ํ•„์š”ํ•œ ๋ชจ๋“  ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ๋ณดํ†ต ์šฉ๋Ÿ‰์ด n๋ฐฑ๋ฉ”๊ฐ€๋กœ n๊ธฐ๊ฐ€๊ฐ€ ๋„˜๋Š” ๊ฒฝ์šฐ๋„ ํ”ํ•˜๋‹ค. ๊ฐ™์€ ์ด๋ฏธ์ง€์—์„œ ์กฐ๊ธˆ ๋ณ€ํ™”ํ–ˆ๋‹ค๊ณ  ๋น„์Šทํ•œ ์šฉ๋Ÿ‰์˜ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์‹œ ๋ฐ›๋Š” ๊ฒƒ์€ ๋น„ํšจ์œจ์ ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ ˆ์ด์–ด ๊ฐœ๋…์„ ์‚ฌ์šฉํ•œ๋‹ค.

  • ์ด๋ฏธ์ง€์— ๋ณ€ํ™”๊ฐ€ ์žˆ์„ ๋•Œ ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, ๊ธฐ์กด ์ด๋ฏธ์ง€์—์„œ ๋ณ€๊ฒฝ๋œ ๋ถ€๋ถ„๋งŒ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์ด๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
  • ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋งŒ๋“ค๊ณ  ์ด๋ฏธ์ง€๋ฅผ runํ•˜๋ฉด, ์ด๋ฏธ์ง€ layer์— writable layer (the โ€œcontainer layerโ€)๊ฐ€ ์ถ”๊ฐ€๋œ๋‹ค. ์—ฌ๊ธฐ์„œ ์ƒˆ๋กœ์šด ํŒŒ์ผ์„ ๋งŒ๋“ค๊ฑฐ๋‚˜, ๊ธฐ์กด ํŒŒ์ผ ์‚ญ์ œํ•˜๊ฑฐ๋‚˜ ํ•˜๋Š” ๋ณ€ํ™”๋“ค์ด ์ €์žฅ๋œ๋‹ค.

์ด๋ฏธ์ง€๋ฅผ ํ’€ ๋ฐ›์œผ๋ฉด ๋ ˆ์ด์–ด๋“ค์€ ๋…๋ฆฝ์ ์œผ๋กœ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•  ๋•Œ๋Š” ์ด ๋ ˆ์ด์–ด๋“ค์„ ์ฐจ๋ก€๋Œ€๋กœ ์Œ“์•„์˜ฌ๋ ค์„œ ํŠน์ • ์œ„์น˜์— ๋งˆ์šดํŠธ๋ฅผ ํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์œผ๋กœ ์ด๋ฏธ์ง€์— ์†ํ•˜๋Š” ๋ ˆ์ด์–ด๋“ค์€ ์ฝ๊ธฐ ์ „์šฉ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ ˆ๋Œ€๋กœ ๋ณ€ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ ์œ„์— ๋งˆ์ง€๋ง‰์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ ์ „์šฉ ์“ฐ๊ธฐ ๊ฐ€๋Šฅํ•œ ๋ ˆ์ด์–ด๋ฅผ ํ•œ ์ธต ๋” ์Œ“๊ณ , ์ปจํ…Œ์ด๋„ˆ์—์„œ ์ผ์–ด๋‚˜๋Š” ๋ชจ๋“  ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ด ๋ ˆ์ด์–ด์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

2. ์—ฐ์Šต

ubuntu ์ปจํ…Œ์ด๋„ˆ

- ์ƒ์„ฑ

ubuntu 16.04 ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ๋œฌ๋‹ค. ๋‚˜๋Š” ์‚ฌ์šฉํ•  ์ด๋ฏธ์ง€๊ฐ€ ์—†์œผ๋ฉด ๋ชป ์“ฐ๋Š” ์ค„ ์•Œ์•˜๋Š”๋ฐ, run ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ ํ•ด๋‹น ์ด๋ฆ„์œผ๋กœ ์ €์žฅ๋œ ์ด๋ฏธ์ง€๊ฐ€ ์—†๋‹ค๋ฉด ๋‹ค์šด๋กœ๋“œ(pull)๋ฅผ ํ•˜๊ณ  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑ, ์‹œ์ž‘๊นŒ์ง€ ํ•ด์ค€๋‹ค ๐Ÿ˜ฏ

โฏ docker run ubuntu:16.04
Unable to find image 'ubuntu:16.04' locally
16.04: Pulling from library/ubuntu
6aa38bd67045: Pull complete
981ae4862c05: Pull complete
5bad8949dcb1: Pull complete
ca9461589e70: Pull complete
Digest: sha256:69bc24edd22c270431d1a9e6dbf57cfc4a77b2da199462d0251b145fdd7fa538
Status: Downloaded newer image for ubuntu:16.04

ํŠน์ • ํ–‰๋™์„ ํ•˜๋ผ๋Š” command๊ฐ€ ์—†์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ์œ„์—์„œ๋Š” ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ ํ›„ ๋ฐ”๋กœ ์ข…๋ฃŒ๋œ๋‹ค. -a option์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ™•์ธํ•ด๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

โฏ docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                      PORTS                    NAMES
d3000f258ecf        ubuntu:16.04                "/bin/bash"              13 seconds ago      Exited (0) 13 seconds ago                            stupefied_robinson

- ์‹คํ–‰

/bin/bash ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด root@container์˜id ๊ฐ€ ์•ž์— ๋œจ๊ณ , ls๋ฅผ ํ•ด๋ณด๋ฉด ๋ฆฌ๋ˆ…์Šค์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ์œ„์™€ ๋˜‘๊ฐ™์€ run์ด์ง€๋งŒ ์•„๋ž˜์˜ ๊ฒฝ์šฐ ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ ์—†์ด ๋ฐ”๋กœ ์‹œ์ž‘๋œ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

  • rm์˜ต์…˜: ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ข…๋ฃŒ๋˜๋ฉด ์ปจํ…Œ์ด๋„ˆ ์ž๋™ ์‚ญ์ œ
  • it์˜ต์…˜: ํ‚ค๋ณด๋“œ ์ž…๋ ฅ์šฉ
  • exit: ์ข…๋ฃŒ ๊ธฐ๋Šฅ
โฏ docker run --rm -it ubuntu:16.04 /bin/bash
root@4be0ed8f8460:/#
root@4be0ed8f8460:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

MySQL์ปจํ…Œ์ด๋„ˆ

โฏ docker run -d -p 3306:3306 \
  -e MYSQL_ALLOW_EMPTY_PASSWORD=true \
  --name mysql \
  mysql:5.7
Unable to find image 'mysql:5.7' locally
5.7: Pulling from library/mysql
8559a31e96f4: Pull complete
d51ce1c2e575: Pull complete
c2344adc4858: Pull complete
fcf3ceff18fc: Pull complete
16da0c38dc5b: Pull complete
b905d1797e97: Pull complete
4b50d1c6b05c: Pull complete
d85174a87144: Pull complete
a4ad33703fa8: Pull complete
f7a5433ce20d: Pull complete
3dcd2a278b4a: Pull complete
Digest: sha256:32f9d9a069f7a735e28fd44ea944d53c61f990ba71460c5c183e610854ca4854
Status: Downloaded newer image for mysql:5.7
091243f216ca14e5d56bbd83a392cb41326ede3e6a7859ee62a239d98960bb26

๋ฌด์Šจ ์ด์œ ์ธ์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ ์ฐธ๊ณ ํ•œ ๋ธ”๋กœ๊ทธ์—์„œ ๋งํ•˜๋Š” mysql -h127.0.0.1 -uroot์˜ ๊ฒฝ์šฐ access๊ฐ€ ๊ฑฐ์ ˆ๋œ๋‹ค. ๊ทธ๋ž˜์„œ ๊ตฌ๊ธ€๋ง์„ ํ•ด๋ณด๋‹ค๊ฐ€ ๊ทธ๋ƒฅ ์ปจํ…Œ์ด๋„ˆ๋ฅผ runํ•˜๊ณ  bash shell์— ๋“ค์–ด๊ฐ€์„œ mysql์„ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ํ•˜๋‹ˆ๊นŒ ๋๋‹ค.

โฏ mysql -h127.0.0.1 -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
โฏ docker exec -it aaa732ddb37544 /bin/bash
root@aaa732ddb375:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>

3. command

docker run

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

docker ps

์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ์ปค๋งจ๋“œ.

# ์‹คํ–‰ ์ค‘์ธ ๋„์ปค๊ฐ€ ์—†์„ ๊ฒฝ์šฐ 
โฏ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
ad28f0249913        mysql:5.7           "docker-entrypoint.sโ€ฆ"   5 minutes ago       Up 5 minutes        0.0.0.0:3306->3306/tcp, 33060/tcp   mysql

docker ps -a

์‹คํ–‰์ด ์ข…๋ฃŒ๋œ ๊ฒƒ์„ ํฌํ•จํ•ด์„œ ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋ณด๋Š” ์ปค๋งจ๋“œ ๋ฐ ์˜ต์…˜

โฏ docker ps -a
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                     PORTS                    NAMES
8e55741a8b3e        chloeyeeunlee/rolex:0.2.0   "gunicorn --bind 0.0โ€ฆ"   7 weeks ago         Exited (255) 6 weeks ago   0.0.0.0:8000->8000/tcp   rolex3
bc5dfa15cef2        chloeyeeunlee/rolex:0.2.0   "gunicorn --bind 0.0โ€ฆ"   7 weeks ago         Created                                             rolex2
4acad6b533be        433bed511d1b                "gunicorn --bind 0.0โ€ฆ"   7 weeks ago         Exited (0) 7 weeks ago                              rolex
4b8d6e0590bd        redis:5                     "docker-entrypoint.sโ€ฆ"   8 weeks ago         Exited (0) 7 weeks ago                              happy_villani
95dea880cdf4        docker/getting-started      "nginx -g 'daemon ofโ€ฆ"   8 weeks ago         Exited (255) 7 weeks ago   0.0.0.0:80->80/tcp       tender_perlman

docker images

์ƒ์„ฑ๋œ ํ˜น์€ ๋‹ค์šด๋กœ๋“œ ๋œ ์ด๋ฏธ์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ์ปค๋งจ๋“œ

โฏ docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
chloeyeeunlee/rolex      0.1.0               467b4e02da19        7 weeks ago         986MB
chloeyeeunlee/rolex      0.2.0               467b4e02da19        7 weeks ago         986MB
python                   3                   659f826fabf4        7 weeks ago         934MB
redis                    5                   a4d3716dbb72        2 months ago        98.3MB
docker/getting-started   latest              3c156928aeec        2 months ago        24.8MB

docker ์ค‘์ง€

container ID๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๋ฉด ์ค‘์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.

โฏ docker stop ad28f0249913
ad28f0249913
โฏ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

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

์ด๋ฏธ์ง€๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ ˆ์ด์–ด๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, deleted๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ ๋œจ๋Š” ๊ฒƒ์€ ๋ชจ๋“  ๋ ˆ์ด์–ด๊ฐ€ ์‚ญ์ œ๋˜์—ˆ๋‹ค๋Š” ๋œป์ด๋‹ค. ๋‹ค์‹œ ์ด๋ฏธ์ง€๋ฅผ ๋“ค์–ด๊ฐ€๋ฉด ํ•ด๋‹น ID๋ฅผ ๊ฐ€์ง„ ์ด๋ฏธ์ง€๊ฐ€ ์‚ญ์ œ๋œ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

โฏ docker rmi 3c156928aeec
Untagged: docker/getting-started:latest
Untagged: docker/getting-started@sha256:d2c4fb0641519ea208f20ab03dc40ec2a5a53fdfbccca90bef14f870158ed577
Deleted: sha256:3c156928aeec9595a140d3e9bb67fc6849650a0a756bbb0b1690ce9a4ddca884
Deleted: sha256:bd0923edebaabd47c31d4f79115f9cbd91e6045c9b2585f02b346af81a6d3dbd
Deleted: sha256:0d6528f3488cda7f74d825579182af56cbdd7fed5bccacfa3042834b514157ac
Deleted: sha256:ec7d8444b0ff84cd1e55ec191abe60e26f996ac883d87dcb50fdca507f2af8be
Deleted: sha256:beee9f30bc1f711043e78d4a2be0668955d4b761d587d6f60c2c8dc081efb203
โฏ docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
ubuntu                16.04               c522ac0d6194        42 hours ago        126MB
mysql                 5.7                 9cfcce23593a        4 weeks ago         448MB
chloeyeeunlee/rolex   0.1.0               467b4e02da19        7 weeks ago         986MB
chloeyeeunlee/rolex   0.2.0               467b4e02da19        7 weeks ago         986MB
chloeyeeunlee/rolex   <none>              433bed511d1b        7 weeks ago         986MB
python                3                   659f826fabf4        7 weeks ago         934MB
redis                 5                   a4d3716dbb72        2 months ago        98.3MB
profile
์ด์‚ฌ๊ฐ„ ๋ธ”๋กœ๊ทธ: yenilee.github.io

0๊ฐœ์˜ ๋Œ“๊ธ€