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:4000 ์์ ์๋ฒ๋ฅผ ํ์ธํ ์ ์๋ค.

๋์ปค ์ปจํ ์ด๋๋ฅผ ๋์ด ํ ๋ค๋ฅธ ํฐ๋ฏธ๋์์ ์๋ ๋ช ๋ น์ด๋ฅผ ํ์ธํด๋ณธ๋ค.

๋ค์๊ณผ ๊ฐ์ ๋ช ๋ น์ด๋ฅผ ํ์ธํ ์ ์๋ค.
๋ง์ฝ ์ปจํ ์ด๋๊ฐ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ๋ฐ๋ชฌ์ผ๋ก ๋์๊ฐ๋์ง ํ์ธํ๊ธฐ ์ํด์๋ -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:
[hostname]= gcr.io
[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