githubEdit

Lab1

์„ธ์…˜ ๋ชฉํ‘œ

  • Docker Container build, run, debug

  • Docker Hub๋กœ๋ถ€ํ„ฐ Docker images pull ํ•˜๊ธฐ

  • Google Container Registry ์— Docker image push ํ•˜๊ธฐ

Google Cloud

Cloud Shell ์€ development tools ์™€ ๋กœ๋“œ๋˜๋Š” ๊ฐ€์ƒ ๋จธ์‹ ์ด๋‹ค.

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

Auth list ํ™•์ธ

๋„์ปค ๋ฐ๋ชฌ์€ hello-world ์ด๋ฏธ์ง€๋ฅผ ๋กœ์ปฌ์—์„œ ์ฐพ์ง€ ๋ชปํ•˜๋ฉด Docker Hub์—์„œ ์ด๋ฏธ์ง€๋ฅผ pullํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์‹คํ–‰ํ•œ๋‹ค.

์ด๋ฏธ์ง€๋ฅผ ํ’€ ํ•œ ํ›„ ๋‹ค์‹œ ํ•ด๋‹น ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด ์ด์ œ docker daemon์€ local registry์—์„œ ์ด๋ฏธ์ง€๋ฅผ ์ฐพ๊ณ , ๊ทธ ์ด๋ฏธ์ง€๋กœ๋ถ€ํ„ฐ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

Build

  • The initial line specifies the base parent image, which in this case is the official Docker image for node version long term support (lts).

  • In the second, you set the working (current) directory of the container.

  • In the third, you add the current directory's contents (indicated by the "." ) into the container.

  • Then expose the container's port so it can accept connections on that port and finally run the node command to start the application.

node application

์œ„ ํŒŒ์ผ ์ž‘์„ฑ ํ›„ image๋ฅผ buildํ•œ๋‹ค.

  • -t ๋ช…๋ น์–ด๋Š” name: tag ๋กœ ํƒœ๊ทธ๋ฅผ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•œ ๋ช…๋ น์–ด.

  • ๋”ฐ๋ผ์„œ ์ด๋ฏธ์ง€์˜ ์ด๋ฆ„์€ node-app ์ด๊ณ , tag๋Š” 0.1์ด ๋œ๋‹ค.

  • ํƒœ๊ทธ๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด latest ๋กœ ์ €์žฅ๋œ๋‹ค. ์ด๋ ‡๊ฒŒ ๋˜๋ฉด ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๊ฐ€ ์ƒ๊ฒผ์„ ๋•Œ ํ—ท๊ฐˆ๋ฆฌ๊ธฐ ๋•Œ๋ฌธ์— ํƒœ๊ทธ๋ฅผ ๋ฐ˜๋“œ์‹œ ์ €์žฅํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๋‹ค.

์ด๋ฏธ์ง€ ๋นŒ๋“œ ํ›„ ๋„์ปค ์ด๋ฏธ์ง€ ๋ชฉ๋ก์„ ํ™•์ธํ•œ๋‹ค.

Run

์œ„์—์„œ ๋นŒ๋“œํ•œ ์ด๋ฏธ์ง€ ๊ธฐ๋ฐ˜์˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

  • โ€”name ์€ ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๋ช…๋ น์–ด์ด๋‹ค.

  • -p ๋Š” ๋„์ปค๊ฐ€ ํ˜ธ์ŠคํŠธ์˜ ํฌํŠธ 4000๋ฒˆ์„ ์ปจํ…Œ์ด๋„ˆ์˜ 80๋ฒˆ ํฌํŠธ๋กœ ๋งคํ•‘ํ•˜๋„๋กํ•œ๋‹ค.

  • ๋”ฐ๋ผ์„œ ํ˜ธ์ŠคํŠธ๋Š” http://localhost:4000arrow-up-right ์—์„œ ์„œ๋ฒ„๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋„์šด ํ›„ ๋‹ค๋ฅธ ํ„ฐ๋ฏธ๋„์—์„œ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ํ™•์ธํ•ด๋ณธ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๋งŒ์•ฝ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ๋ฐ๋ชฌ์œผ๋กœ ๋Œ์•„๊ฐ€๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” -d flag๋ฅผ ๋ถ™์ธ๋‹ค.

๋„์ปค ๋‚ด๋ ธ๋‹ค๊ฐ€ background์—์„œ run ํ•˜๋„๋ก ํ•˜๋Š” ๋ช…๋ น์–ด

์ปจํ…Œ์ด๋„ˆ ์•„์ด๋””๋ฅผ ํ†ตํ•ด ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•œ๋‹ค.

app.js ํŒŒ์ผ ๋ณ€๊ฒฝ ํ›„ ๋‹ค์‹œ ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œํ•˜๊ณ  ์ƒˆ๋กœ์šด ํƒœ๊ทธ๋ฅผ ๋ถ™์ธ๋‹ค.

step2 ์—์„œ๋Š” ์ด๋ฏธ ์กด์žฌํ•˜๋Š” cache layer๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

Step3 ๋ถ€ํ„ฐ๋Š” app.js์—์„œ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์žˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— layer๋“ค๋„ ์ˆ˜์ •๋œ๋‹ค.

์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ์ด์šฉํ•œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

์ด๋ฏธ ํ˜ธ์ŠคํŠธ์˜ 4000๋ฒˆ ํฌํŠธ๋ฅผ ์‚ฌ์šฉ์ค‘์ด๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค๋ฅธ ํฌํŠธ๋ฒˆํ˜ธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

Debug

์ปจํ…Œ์ด๋„ˆ ์•„์ด๋””๋ฅผ ํ†ตํ•ด ๋„์ปค ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•œ๋‹ค.

์ปจํ…Œ์ด๋„ˆ์•ˆ์—์„œ interactive Bash session ์‹คํ–‰

  • -it flag๋Š” pseudo-tty๋ฅผ ํ• ๋‹นํ•จ์œผ๋กœ์จ ์ปจํ…Œ์ด๋„ˆ์™€ ์ƒํ˜ธ์ž‘์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.

  • bash๋Š” WORKDIR ์ธ /app ์—์„œ ์‹คํ–‰๋œ๋‹ค๋Š” ๊ฒƒ์„ ๊ธฐ์–ตํ•˜์ž. (Dockerfile ์—์„œ ์ž‘์„ฑํ•จ)

Publish

์ด์ œ ์ด๋ฏธ์ง€๋ฅผ Google Container Registry (gcr)์— ํ‘ธ์‹œํ•ด๋ณด์ž!

๊ทธ ํ›„ ์ปจํ…Œ์ด๋„ˆ์™€ ์ด๋ฏธ์ง€๋“ค์„ ์‚ญ์ œํ•  ๊ฒƒ์ด๊ณ , ๊ทธ ๋‹ค์Œ ํ’€ํ•˜๊ณ  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•  ๊ฒƒ์ด๋‹ค.

gcr์— ์ด๋ฏธ์ง€๋ฅผ ํ‘ธ์‹œํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ด๋ฏธ์ง€ ์ด๋ฆ„์„ registry name์œผ๋กœ ํƒœ๊ทธํ•ด์•ผํ•œ๋‹ค.

ํ˜•์‹์€ [hostname]/[project-id]/[image]:[tag] ์ด๋‹ค.

For gcr:

  • [project-id]= your project's ID

  • [image]= your image name

  • [tag]= any string tag of your choice. If unspecified, it defaults to "latest".

project ID๋Š” ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ด ํ™•์ธํ•œ๋‹ค.

node-app:0.2 ๋ฅผ ํƒœ๊น…ํ•ด๋ณด์ž.

์ด์ œ ์ด ์ด๋ฏธ์ง€๋ฅผ gcr์— ํ‘ธ์‹œํ•ด๋ณด์ž.

์ด์ œ Google Cloud์—์„œ ์ด๋ฏธ์ง€๊ฐ€ ์ž˜ ํ‘ธ์‹œ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

์ด๋ฏธ์ง€ ํ…Œ์ŠคํŠธ

๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์‹œ๋„ ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๊ฐ„๋‹จํžˆ ์กด์žฌํ•˜๋˜ ๊ธฐ์กด์˜ ์ปจํ…Œ์ด๋„ˆ๋“ค์„ ์‚ญ์ œํ•œ๋‹ค.

node image๋ฅผ ์ง€์šฐ๊ธฐ ์ „์— node:lts ์˜ child images ๋“ค๋„ ์‚ญ์ œํ•ด์•ผํ•œ๋‹ค.

๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

์ด์ œ ์ด๋ฏธ์ง€๋ฅผ pull ํ•˜๊ณ  ์‹คํ–‰ํ•ด๋ณด์ž

Last updated