A A
[Docker] Docker Container ๋ช…๋ น์–ด (with Ngnix Container ์‹คํ–‰)
์ด๋ฒˆ์—๋Š” Docker Container ๋ช…๋ น์–ด๋“ค์— ๋ฐํ•˜์—ฌ ํ•œ๋ฒˆ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

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

Docker Container ๊ด€๋ จ ๋ช…๋ น์–ด

๋„์ปค ์ด๋ฏธ์ง€๋Š” ์ปจํ…Œ์ด๋„ˆ ๋™์ž‘๊ณผ ๊ด€๋ จ๋œ ์ฝ˜ํ…์ธ ๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์ด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ์˜ ๋™์ž‘์ด ์ด๋ฃจ์–ด ์ง‘๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ปจํ…Œ์ด๋„ˆ ๋ช…๋ น ๋Œ€๋ถ€๋ถ„์ด ์„œ๋น„์Šค ์‹คํ–‰ ๋ฐ ์šด์˜๊ณผ ๊ด€๋ จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

Container๋Š” Process๋‹ค

๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋Š” ์•ž์„œ ๋ฐฐ์šด ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๋งŒ๋“ค์–ด์ง€๋Š” ์Šค๋ƒ…์ˆ(snapshot)์ž…๋‹ˆ๋‹ค. ์ด ์Šค๋ƒ…์ˆ์€ ์ฝ๊ธฐ ์ „์šฉ์˜ ๋„์ปค ์ด๋ฏธ์ง€ ๋ ˆ์ด์–ด๋ฅผ (๋ถˆ๋ณ€์˜ ์œ ๋‹‰์Šค ํŒŒ์ผ ์‹œ์Šคํ…œ์„) ๋ณต์ œํ•œ ๊ฒƒ์ด๊ณ , ๊ทธ ์œ„์— ์ฝ๊ณ  ์“ฐ๊ธฐ๊ฐ€ ๊ฐ€๋Šฅํ•œ ์ปจํ…Œ์ด๋„ˆ ๋ ˆ์ด์–ด๋ฅผ ๊ฒฐํ•ฉํ•˜๋ฉด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ ˆ์ด์–ด๋“ค๋งŒ ๊ฐ€์ง€๊ณ  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋™์ž‘ํ•˜๋Š” ๊ฒƒ์ผ๊นŒ์š”?

 

์ปดํ“จํ„ฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋™์ž‘์€ ํ”„๋กœ์„ธ์Šค(process)๋ฅผ ํ†ตํ•ด ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค. “์ปจํ…Œ์ด๋„ˆ๋Š” ๊ฒฉ๋ฆฌ๋œ ๊ณต๊ฐ„์—์„œ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋™์ž‘ํ•˜๋Š” ๊ธฐ์ˆ .” ์ด๋ผ๋Š” ๋ง์„ ๊ธฐ์–ต ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ปจํ…Œ์ด๋„ˆ๋Š” ๋ฐ”๋กœ ํ”„๋กœ์„ธ์Šค ๊ฒฉ๋ฆฌ ๊ธฐ์ˆ (namespaces, cgroups, chroot)์˜ ํ‘œ์ค€์œผ๋กœ ์ •์˜๋œ OCI(Open Container Initiative)๋กœ ์ปจํ…Œ์ด๋„ˆ ํฌ๋งท๊ณผ ๋Ÿฐํƒ€์ž„์— ๋Œ€ํ•œ ๊ฐœ๋ฐฉํ˜• ์—…๊ณ„ ํ‘œ์ค€์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•œ ๋ชฉ์ ์œผ๋กœ ๋ฆฌ๋ˆ…์Šค ํŒŒ์šด๋ฐ์ด์…˜(Linux Foundation)์˜ ์ง€์›์„ ๋ฐ›์•„ ๊ตฌ์„ฑ๋œ ์˜คํ”ˆ ํ”„๋กœ์ ํŠธ ์ž…๋‹ˆ๋‹ค.

 

๋ช…๋ น์–ด docker run์„ ์‚ฌ์šฉํ•˜๋ฉด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋™์ž‘ํ•˜๊ฒŒ ๋˜๊ณ , ๊ฐ€์ƒ์˜ ๊ฒฉ๋ฆฌ ํ™˜๊ฒฝ์— ๋…๋ฆฝ๋œ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. ๋งˆ์น˜ ์„œ๋ฒ„ ํ˜ธ์ŠคํŠธ ์šด์˜์ฒด์ œ๊ฐ€ ๋…๋ฆฝ์ ์œผ๋กœ ๋™์ž‘ํ•˜๋Š” ๊ฒƒ๊ณผ ์œ ์‚ฌํ•˜๋‹ค๊ณ  ๋ณด์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฆฌ๋ˆ…์Šค ํ˜ธ์ŠคํŠธ ์šด์˜์ฒด์ œ๋ฅผ ๋ถ€ํŒ…ํ•˜๋ฉด PID 1๋ฒˆ์€ init(systemd) ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋™์ž‘ํ•˜๋ฉฐ ์ด ํ”„๋กœ์„ธ์Šค๋Š” ๋‚˜๋จธ์ง€ ๋ชจ๋“  ์‹œ์Šคํ…œ ํ”„๋กœ์„ธ์Šค์˜ ๋ถ€๋ชจ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

 

์ด์ฒ˜๋Ÿผ ๋…๋ฆฝ๋œ ํ˜ธ์ŠคํŠธ ์šด์˜์ฒด์ œ๋Š” init ํ”„๋กœ์„ธ์Šค์™€ ๊ฐ™์€ ์ตœ์ƒ์œ„ ๋ถ€๋ชจ ํ”„๋กœ์„ธ์Šค๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ์˜ PID 1๋ฒˆ ํ”„๋กœ์„ธ์Šค๋Š” init ํ”„๋กœ์„ธ์Šค์ผ๊นŒ? ๊ฐ„๋‹จํ•œ ํ…Œ์ŠคํŠธ๋ฅผ ํ†ตํ•ด ํ™•์ธํ•ด ๋ณด๊ฐฐ์Šต๋‹ˆ๋‹ค.

# ํ˜„์žฌ host์—์„œ ์‹คํ–‰์ค‘์ธ shell process id
toby@tobykakao:~$ echo $$
3271

# centos 8 ๋ฒ„์ „ ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ ํ›„ Container bash ๋ชจ๋“œ๋กœ ์ ‘์†
toby@tobykakao:~$ docker run -it centos:8 bash
[root@9edeb3472cb8 /]# echo $$
1
[root@9edeb3472cb8 /]# exit
exit

# ๋‹ค๋ฅธ ํ„ฐ๋ฏธ๋„์—์„œ ์‹คํ–‰์ค‘์ธ PID ์กฐํšŒ
toby@tobykakao:~$ ps -ef | grep 3271
toby        3271    3263  0 11:38 pts/0    00:00:00 bash
toby       13626    3271 99 11:57 pts/0    00:00:00 ps -ef
toby       13627    3271  0 11:57 pts/0    00:00:00 grep --color=auto 3271
# /proc์™€ ํ•˜์œ„ namespace(ns) ๊ฒฝ๋กœ ํ™•์ธ
toby@tobykakao:~$ cd /proc/3271
toby@tobykakao:/proc/3271$ ls -l
total 0
dr-xr-xr-x  2 toby toby 0 Nov  1 11:59 attr
-rw-r--r--  1 toby toby 0 Nov  1 11:59 autogroup
-r--------  1 toby toby 0 Nov  1 11:59 auxv
-r--r--r--  1 toby toby 0 Nov  1 11:59 cgroup
--w-------  1 toby toby 0 Nov  1 11:59 clear_refs
-r--r--r--  1 toby toby 0 Nov  1 11:55 cmdline
-rw-r--r--  1 toby toby 0 Nov  1 11:59 comm
-rw-r--r--  1 toby toby 0 Nov  1 11:59 coredump_filter
-r--r--r--  1 toby toby 0 Nov  1 11:59 cpuset
lrwxrwxrwx  1 toby toby 0 Nov  1 11:55 cwd -> /proc/3271
-r--------  1 toby toby 0 Nov  1 11:55 environ
lrwxrwxrwx  1 toby toby 0 Nov  1 11:54 exe -> /usr/bin/bash
dr-x------  2 toby toby 4 Nov  1 11:55 fd
dr-xr-xr-x  2 toby toby 0 Nov  1 11:59 fdinfo
-rw-r--r--  1 toby toby 0 Nov  1 11:59 gid_map
-r--------  1 toby toby 0 Nov  1 11:59 io
-r--------  1 toby toby 0 Nov  1 11:59 ksm_merging_pages
-r--------  1 toby toby 0 Nov  1 11:59 ksm_stat
-r--r--r--  1 toby toby 0 Nov  1 11:59 latency
-r--r--r--  1 toby toby 0 Nov  1 11:59 limits
-rw-r--r--  1 toby toby 0 Nov  1 11:59 loginuid
dr-x------  2 toby toby 0 Nov  1 11:55 map_files
-r--r--r--  1 toby toby 0 Nov  1 11:55 maps
-rw-------  1 toby toby 0 Nov  1 11:59 mem
-r--r--r--  1 toby toby 0 Nov  1 11:59 mountinfo
-r--r--r--  1 toby toby 0 Nov  1 11:59 mounts
-r--------  1 toby toby 0 Nov  1 11:59 mountstats
dr-xr-xr-x 54 toby toby 0 Nov  1 11:59 net
dr-x--x--x  2 toby toby 0 Nov  1 11:59 ns
-r--r--r--  1 toby toby 0 Nov  1 11:59 numa_maps
-rw-r--r--  1 toby toby 0 Nov  1 11:59 oom_adj
-r--r--r--  1 toby toby 0 Nov  1 11:59 oom_score
-rw-r--r--  1 toby toby 0 Nov  1 11:59 oom_score_adj
-r--------  1 toby toby 0 Nov  1 11:59 pagemap
-r--------  1 toby toby 0 Nov  1 11:59 personality
-rw-r--r--  1 toby toby 0 Nov  1 11:59 projid_map
lrwxrwxrwx  1 toby toby 0 Nov  1 11:55 root -> /
-rw-r--r--  1 toby toby 0 Nov  1 11:59 sched
-r--r--r--  1 toby toby 0 Nov  1 11:59 schedstat
-r--r--r--  1 toby toby 0 Nov  1 11:59 sessionid
-rw-r--r--  1 toby toby 0 Nov  1 11:59 setgroups
-r--r--r--  1 toby toby 0 Nov  1 11:59 smaps
-r--r--r--  1 toby toby 0 Nov  1 11:59 smaps_rollup
-r--------  1 toby toby 0 Nov  1 11:59 stack
-r--r--r--  1 toby toby 0 Nov  1 11:38 stat
-r--r--r--  1 toby toby 0 Nov  1 11:59 statm
-r--r--r--  1 toby toby 0 Nov  1 11:55 status
-r--------  1 toby toby 0 Nov  1 11:59 syscall
dr-xr-xr-x  3 toby toby 0 Nov  1 11:59 task
-rw-r--r--  1 toby toby 0 Nov  1 11:59 timens_offsets
-r--r--r--  1 toby toby 0 Nov  1 11:59 timers
-rw-rw-rw-  1 toby toby 0 Nov  1 11:59 timerslack_ns
-rw-r--r--  1 toby toby 0 Nov  1 11:59 uid_ma
# ํ˜ธ์ŠคํŠธ ์šด์˜์ฒด์ œ์˜ PID 1๋ฒˆ๊ณผ ํ˜„์žฌ host์—์„œ ์‹คํ–‰์ค‘์ธ shell process ๋น„๊ต
toby@tobykakao:/$ sudo ls -l /proc/1/ns
total 0
lrwxrwxrwx 1 root root 0 Nov  1 11:34 cgroup -> 'cgroup:[4026531835]'
lrwxrwxrwx 1 root root 0 Nov  1 12:00 ipc -> 'ipc:[4026531839]'
lrwxrwxrwx 1 root root 0 Nov  1 11:35 mnt -> 'mnt:[4026531841]'
lrwxrwxrwx 1 root root 0 Nov  1 12:00 net -> 'net:[4026531840]'
lrwxrwxrwx 1 root root 0 Nov  1 11:55 pid -> 'pid:[4026531836]'
lrwxrwxrwx 1 root root 0 Nov  1 12:00 pid_for_children -> 'pid:[4026531836]'
lrwxrwxrwx 1 root root 0 Nov  1 12:00 time -> 'time:[4026531834]'
lrwxrwxrwx 1 root root 0 Nov  1 12:00 time_for_children -> 'time:[4026531834]'
lrwxrwxrwx 1 root root 0 Nov  1 12:00 user -> 'user:[4026531837]'
lrwxrwxrwx 1 root root 0 Nov  1 12:00 uts -> 'uts:[4026531838]'

toby@tobykakao:/$ sudo ls -l /proc/3271/ns
total 0
lrwxrwxrwx 1 toby toby 0 Nov  1 12:01 cgroup -> 'cgroup:[4026531835]'
lrwxrwxrwx 1 toby toby 0 Nov  1 12:01 ipc -> 'ipc:[4026531839]'
lrwxrwxrwx 1 toby toby 0 Nov  1 12:01 mnt -> 'mnt:[4026531841]'
lrwxrwxrwx 1 toby toby 0 Nov  1 12:01 net -> 'net:[4026531840]'
lrwxrwxrwx 1 toby toby 0 Nov  1 12:01 pid -> 'pid:[4026531836]'
lrwxrwxrwx 1 toby toby 0 Nov  1 12:01 pid_for_children -> 'pid:[4026531836]'
lrwxrwxrwx 1 toby toby 0 Nov  1 12:01 time -> 'time:[4026531834]'
lrwxrwxrwx 1 toby toby 0 Nov  1 12:01 time_for_children -> 'time:[4026531834]'
lrwxrwxrwx 1 toby toby 0 Nov  1 12:01 user -> 'user:[4026531837]'
lrwxrwxrwx 1 toby toby 0 Nov  1 12:01 uts -> 'uts:[4026531838]'

์œ„์˜ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ด ๋ณด๋ฉด docker run~ ์ˆ˜ํ–‰ ์‹œ PID ๋„ค์ž„์ŠคํŽ˜์ด์Šค ์ปค๋„ ๊ธฐ๋Šฅ์„ ํ†ตํ•ด ์‹œ์Šคํ…œ์˜ 1๋ฒˆ ํ”„๋กœ์„ธ์Šค(init)์˜ PID(4026531836)๋ฅผ ๊ณต์œ ํ•˜๊ณ  ๊ทธ ํ•˜์œ„๋กœ ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ฒฉ๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๊ฒฉ๋ฆฌ๋œ ํ”„๋กœ์„ธ์Šค๋ฅผ ๋ฃจํŠธ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” chroot ์ปค๋„ ๊ธฐ๋Šฅ์„ ํ†ตํ•ด ๋…๋ฆฝ๋œ 1๋ฒˆ PID๋ฅผ ๊ฐ–๊ฒŒ ๋˜๊ณ , ์ปจํ…Œ์ด๋„ˆ ๋™์ž‘ ์‹œ ํ•„์š”ํ•œ ์ž์›์— ๋Œ€ํ•œ ํ• ๋‹น์€ cgroups ์ปค๋„ ๊ธฐ๋Šฅ์„ ํ†ตํ•ด ์ด๋ฃจ์–ด์ง‘๋‹ˆ๋‹ค.

 

๋”ฐ๋ผ์„œ, ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ปจํ…Œ์ด๋„ˆ์— ์ œ๊ณต๋˜๋Š” ์ปค๋„ ๊ธฐ์ˆ ์„ ์ดํ•ดํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด์ œ๋ถ€ํ„ฐ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰, ์šด์˜, ๊ด€๋ฆฌํ•˜๋Š” ๋ช…๋ น์–ด์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


Container ์‹คํ–‰

์ปจํ…Œ์ด๋„ˆ์˜ ์‹คํ–‰์„ ์œ„ํ•ด docker run ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜๋ฉด ํ•ด๋‹น ๋„์ปค ์ด๋ฏธ์ง€ ๋ณต์‚ฌ๋ณธ ์Šค๋ƒ…์ˆ ๋ ˆ์ด์–ด ์œ„์— ์ฝ๊ณ  ์“ฐ๊ธฐ๊ฐ€ ๊ฐ€๋Šฅํ•œ ์ปจํ…Œ์ด๋„ˆ ๋ ˆ์ด์–ด๋ฅผ ์ถ”๊ฐ€ํ•œ ๋’ค docker start ๋ช…๋ น์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ์‹คํ–‰๋œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์กฐํšŒํ•˜๋Š” ๋ฐฉ๋ฒ•์€ docker ps ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋ฆฌ๋ˆ…์Šค ๋ช…๋ น์–ด์ธ ps(Process Status)๋Š” ๋ฆฌ๋ˆ…์Šค ํ˜ธ์ŠคํŠธ์—์„œ ์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ์„ธ์Šค๋ฅผ ์กฐํšŒํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ด์ฒ˜๋Ÿผ ์ปจํ…Œ์ด๋„ˆ ๋˜ํ•œ ํ”„๋กœ์„ธ์Šค๋ผ๋Š” ์˜๋ฏธ์—์„œ docker ps ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

docker run์€ ์ƒ๋‹นํžˆ ๋งŽ์€ ์˜ต์…˜์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋งŒํผ ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋™์ž‘์„ ์„ธ์„ธํ•˜๊ฒŒ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์˜๋ฏธ์ด๊ธฐ๋„ ํ•˜๋‹ค. ์—ฌ๊ธฐ์„œ๋Š” ์ฃผ์š” ์˜ต์…˜๋งŒ ๋‹ค๋ค„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ํ•œ๋ฒˆ docker run ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์— ์ˆ˜๋™์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ œ์–ดํ•˜๋Š” ๊ณผ์ •์„ ์‹ค์Šตํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

# docker create๋Š” run๊ณผ ๋‹ฌ๋ฆฌ container ๋‚ด๋ถ€ ์ ‘๊ทผ์„ ํ•˜์ง€ ์•Š๊ณ  ์ƒ์„ฑ(snapshot)๋งŒ ์ˆ˜ํ–‰
toby@tobykakao:/$ docker create -it --name container-test1 ubuntu:14.04
Unable to find image 'ubuntu:14.04' locally
14.04: Pulling from library/ubuntu
d1a5a1e51f25: Pull complete 
75f8eea31a63: Pull complete 
a72d031efbfb: Pull complete 
Digest: sha256:64483f3496c1373bfd55348e88694d1c4d0c9b660dee6bfef5e12f43b9933b30
Status: Downloaded newer image for ubuntu:14.04
513f21b43af310b4769680c0e795f087aca3e2b9c6a93998036a1f410cc6aead

toby@tobykakao:/$ docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED              STATUS                       PORTS                               NAMES
513f21b43af3   ubuntu:14.04   "/bin/bash"              About a minute ago   Created                                                          container-test1
# docker ps ๋ช…๋ น์˜ status๋ฅผ ๋ณด๋ฉด start๊ฐ€ ์•„๋‹Œ 'created'์ž„์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค
# ์ƒ์„ฑ๋œ snapshot์„ ๋™์ž‘์‹œํ‚จ๋‹ค.
toby@tobykakao:/$ docker start container-test1
container-test1

toby@tobykakao:/$ docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS         PORTS     NAMES
513f21b43af3   ubuntu:14.04   "/bin/bash"   3 minutes ago   Up 4 seconds             container-test1
# Container์— ์ ‘์†ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. (docker attach ๋ช…๋ น์€ ์‹คํ–‰์ค‘์ธ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ปจํ…Œ์ด๋„ˆ์— ๋‹จ์ˆœํ•œ ์กฐํšŒ ์ž‘์—…์‹œ์— ์œ ์šฉ)
toby@tobykakao:~$ docker attach container-test1
root@513f21b43af3:/# 
root@513f21b43af3:/# exit
exit

# ๋น ์ ธ๋‚˜์˜จ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๊ฐ•์ œ ์ข…๋ฃŒ๋˜์–ด ์‚ญ์ œ๋œ๋‹ค.
toby@tobykakao:~$ docker rm container-test1
container-test1
  • ์œ„์˜ ์ž‘์—…์œผ๋กœ Docker run์„ ์ˆ˜ํ–‰ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋‚˜์˜ต๋‹ˆ๋‹ค.
toby@tobykakao:~$ docker attach container-test1
root@513f21b43af3:/# 
root@513f21b43af3:/# exit
exit

toby@tobykakao:~$ docker rm container-test1
container-test1

toby@tobykakao:~$ docker run -it --name container-test1 ubuntu:14.04 bash
root@f534ea7ec0c3:/# exit
exit

toby@tobykakao:~$ docker rm container-test1
container-test1
# ๋‹ค๋ฅธ ํ„ฐ๋ฏธ๋„์—์„œ docker ps๋ฅผ ํ†ตํ•ด ์‹คํ–‰๋œ container๋ฅผ ์กฐํšŒํ•œ๋‹ค
toby@tobykakao:~$ docker ps
CONTAINER ID   IMAGE         COMMAND   CREATED          STATUS         PORTS   NAMES
eb81a4675f5    ubuntu:14.04  "bash"    45 seconds ago   Up 44 seconds          container-test1

# ์ปจํ…Œ์ด๋„ˆ์˜ ํ˜ธ์ŠคํŠธ๋ช…์„ ์กฐํšŒํ•œ๋‹ค.
$ docker run -it --name container-test1 ubuntu:14.04 hostname
6938b859424f

์ถ”๊ฐ€๋˜๋Š” docker run์˜ ํŠน์ง•์€ ํ˜ธ์ŠคํŠธ ์„œ๋ฒ„์— ubuntu:14.04 ์ด๋ฏธ์ง€๊ฐ€ ๋‹ค์šด๋กœ๋“œ๋˜์–ด ์žˆ์ง€ ์•Š์•„๋„ ๋กœ์ปฌ์— ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋„์ปค ํ—ˆ๋ธŒ์—์„œ ์ž๋™์œผ๋กœ ๋‹ค์šด๋กœ๋“œํ•œ๋‹ค๋Š” ์ ๊ณผ ๋งˆ์ง€๋ง‰์— ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ์— ์‹คํ–‰ํ•  ๋ช…๋ น์„ ์ž…๋ ฅํ•˜๋ฉด ์ปจํ…Œ์ด๋„ˆ ๋™์ž‘๊ณผ ํ•จ๊ป˜ ์ฒ˜๋ฆฌ๋œ๋‹ค๋Š” ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

docker run = [pull] + create + start + [command]

docker run์—์„œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ์˜ต์…˜์€ ์•„๋ž˜ ํ‘œ์— ์ •๋ฆฌํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

์˜ต์…˜ ์„ค๋ช…
-i, --interactive ๋Œ€ํ™”์‹ ๋ชจ๋“œ ์—ด๊ธฐ
-t TTY(๋‹จ๋ง ๋””๋ฐ”์ด์Šค) ํ• ๋‹น
-d, --detach=true ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ ํ›„ ์ปจํ…Œ์ด๋„ˆ ID ๋“ฑ๋ก
--name ์‹คํ–‰๋˜๋Š” ์ปจํ…Œ์ด๋„ˆ์— ์ด๋ฆ„ ๋ถ€์—ฌ(๋ฏธ์ง€์ • ์‹œ ์ž๋™์œผ๋กœ ๋ถ€์—ฌ๋จ; ๋”•์…”๋„ˆ๋ฆฌ ์›Œ๋“œ ๋žœ๋ค ์„ ํƒ)
--rm ์ปจํ…Œ์ด๋„ˆ ์ข…๋ฃŒ ์‹œ ์ž๋™์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ ์ œ๊ฑฐ
--restart ์ปจํ…Œ์ด๋„ˆ ์ข…๋ฃŒ ์‹œ ์ ์šฉํ•  ์žฌ์‹œ์ž‘ ์ •์ฑ… ์ง€์ • (no, on-failure, always, unless-stopped)
--env ์ปจํ…Œ์ด๋„ˆ์˜ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์ง€์ • (--env-file์€ ์—ฌ๋Ÿฌ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ํŒŒ์ผ๋กœ ์ƒ์„ฑํ•˜์—ฌ ์ง€์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•)
-v, --volume=ํ˜ธ์ŠคํŠธ๊ฒฝ๋กœ:์ปจํ…Œ์ด๋„ˆ๊ฒฝ๋กœ ํ˜ธ์ŠคํŠธ ๊ฒฝ๋กœ์™€ ์ปจํ…Œ์ด๋„ˆ ๊ฒฝ๋กœ์˜ ๊ณต์œ  ๋ณผ๋ฅจ ์„ค์ • (Bind mount)
-h ์ปจํ…Œ์ด๋„ˆ์˜ ํ˜ธ์ŠคํŠธ๋ช… ์ง€์ • (๋ฏธ์ง€์ • ์‹œ ์ปจํ…Œ์ด๋„ˆ ID๊ฐ€ ํ˜ธ์ŠคํŠธ๋ช…์œผ๋กœ ๋“ฑ๋ก)
-p [Host ํฌํŠธ]:[Container ํฌํŠธ], --publish ํ˜ธ์ŠคํŠธ ํฌํŠธ์™€ ์ปจํ…Œ์ด๋„ˆ ํฌํŠธ ์—ฐ๊ฒฐ
-P, --publish-all=[true | false] ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์˜ ๋…ธ์ถœ๋œ (expose)๋œ ํฌํŠธ๋ฅผ ํ˜ธ์ŠคํŠธ ์ž„์˜์˜ ํฌํŠธ์— ๊ฒŒ์‹œ
--link=[container:container_id] ๋™์ผ ํ˜ธ์ŠคํŠธ์˜ ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ์™€ ์—ฐ๊ฒฐ ์„ค์ •์œผ๋กœ IP๊ฐ€ ์•„๋‹Œ ์ปจํ…Œ์ด๋„ˆ์˜ ์ด๋ฆ„์„ ์ด์šฉํ•ด ํ†ต์‹ 

ํ•œ๋ฒˆ ์—ฌ๋Ÿฌ๊ฐ€์ง€ docker run ๋ช…๋ น์„ ์‚ฌ์šฉํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

toby@tobykakao:~$ docker pull mysql:8.0
8.0: Pulling from library/mysql
8b4274ea61c5: Already exists 
08ba006fa9b4: Already exists 
92a1aa4ee2ea: Already exists 
df48654477e3: Already exists 
a3bc7a62e19a: Already exists 
ac2152ccfb17: Pull complete 
4855413356a2: Pull complete 
e050fccf8a37: Pull complete 
f0f86890bcfb: Pull complete 
92dde3d18839: Pull complete 
ad11f03a0bf4: Pull complete 
Digest: sha256:bf79508626d6cad5bd82ea762109690e42467b1eefedab27946eccd69ab23069
Status: Downloaded newer image for mysql:8.0
docker.io/library/mysql:8.0
toby@tobykakao:~$ docker images | grep mysql
mysql8                  1.0       257c7d00682b   35 hours ago   618MB
mysql                   8         07b15f39a8d0   2 weeks ago    600MB
mysql                   8.0       e5b1f8113899   2 weeks ago    608MB
toby@tobykakao:~$ docker run -it mysql:8.0 /bin/bash
bash-5.1# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.4"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.4"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.4"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:4:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"

ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.4
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.4
# Container Stop - docker ps -a๋กœ ์กฐํšŒ
toby@tobykakao:~$ docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                        PORTS                               NAMES
b89bf83a0bf6   mysql:8.0      "docker-entrypoint.s\u2026"   5 minutes ago    Exited (1) 2 seconds ago                                          interesting_volhard
9edeb3472cb8   centos:8       "bash"                   28 minutes ago   Exited (0) 27 minutes ago                                         optimistic_blackwell
b0efa09a7449   centos:8       "bash"                   29 minutes ago   Exited (130) 28 minutes ago                                       sweet_hofstadter
da6c698a2077   httpd:latest   "/bin/bash"              4 days ago       Exited (129) 4 days ago                                           webserver
2f2917a74b78   nginx          "/docker-entrypoint.\u2026"   3 weeks ago      Exited (255) 2 weeks ago      0.0.0.0:80->80/tcp, :::80->80/tcp   webapp
8ad81ee3e360   busybox        "echo 'Hello World'"     3 weeks ago      Exited (0) 3 weeks ago                                            zealous_jones
12a314e0ce74   busybox        "sh"                     3 weeks ago      Exited (0) 3 weeks ago                                            clever_archimedes
1d28ecb555b4   busybox        "sh"                     3 weeks ago      Exited (0) 3 weeks ago          

# ์ปจํ…Œ์ด๋„ˆ stop! ํ›„ docker ps -a๋กœ ์กฐํšŒ.
toby@tobykakao:~$ docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS                     PORTS                  NAMES
ba5adeb0ddcb   mysql:5.7     "docker-entrypoint.s…"   54 seconds ago  Exited (0) 3 seconds ago                          competent_chaplygin
...

# docker start๋กœ ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„, ID๋ฅผ ํ†ตํ•ด ์‹œ์ž‘ ๊ฐ€๋Šฅ.
toby@tobykakao:~$ docker start ba5adeb0ddcb
ba5adeb0ddcb

# docker ps
toby@tobykakao:~$ docker ps
CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS         PORTS                       NAMES
ba5adeb0ddcb   mysql:5.7     "docker-entrypoint.s…"   About a minute ago   Up 5 seconds    3306/tcp, 33060/tcp    upbeat_ellis
# docker exec๋ฅผ ์ด์šฉํ•˜์—ฌ container์— ์ ‘๊ทผ.
toby@tobykakao:~$ docker exec -it ba5adeb0ddcb bash
root@ba5adeb0ddcb:/# cd /var/lib/mysql
root@ba5adeb0ddcb:/var/lib/mysql# ls
... dockerdb

# ์ข…๋ฃŒ์‹œํ‚ค์ง€ ์•Š๊ณ  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋น ์ ธ๋‚˜๊ฐ€๋ ค๋ฉด ctrl + p + q๋ฅผ ๋™์‹œ์— ์ž…๋ ฅ.
root@ba5adeb0ddcb:/#

# ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€ IP ํ™•์ธ. ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์€ ๋„์ปค์—์„œ ์ž๋™ ์ง€์ •๋จ.
toby@tobykakao:~$ docker ps
CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS         PORTS                       NAMES
4f8e315344ef   mysql:5.7     "docker-entrypoint.s…"   5 minutes ago    Up 5 minutes   3306/tcp, 33060/tcp        flamboyant_nash

$ docker inspect flamboyant_nash | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.5",
            "IPAddress": "172.17.0.5",

# ์ปจํ…Œ์ด๋„ˆ ์žฌ์ ‘์†.
toby@tobykakao:~$ docker exec -it flamboyant_nash bash
root@ba5adeb0ddcb:/#

# ์œ„ ์‹ค์Šต๊ณผ ๊ฐ™์€ ๋ช…๋ น์„ ๋‹ค๋ฅธ ํ„ฐ๋ฏธ๋„์—์„œ ์ƒˆ๋กœ ์‹คํ–‰ํ•˜๋ฉด ์ƒˆ๋กœ์šด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ƒˆ๋กœ์šด ์ด๋ฆ„์œผ๋กœ ์‹คํ–‰๋จ.
toby@tobykakao:~$ docker run -it mysql:5.7 bash
root@ba5adeb0ddcb:/#

Container ๋ชจ๋‹ˆํ„ฐ๋ง ๋„๊ตฌ cAdvisor Container ์‹คํ–‰

MacBook - ARM64 ํ™˜๊ฒฝ์—์„œ๋Š” ์ž‘๋™ X → ์ง€์› ์•ˆํ•จ. (์ œ๊ฐ€ ํ…Œ์ŠคํŠธ ํ•ด๋ณด๊ธฐ์—”..? ์•„๋‹์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.)

  • ์„œ๋น„์Šค ์šด์˜์„ ํ•˜๋ฉด์„œ ํ•„์š”ํ•œ ์‹œ์Šคํ…œ Metric(CPU/๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋ฅ , ๋„คํŠธ์›Œํฌ ํŠธ๋ž˜ํ”ฝ ๋“ฑ)์„ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜๋ฉด์„œ ํŠน์ด์‚ฌํ•ญ์ด ์žˆ์„ ๋•Œ ๋Œ€์‘ํ•˜๊ธฐ ์œ„ํ•ด ๋ชจ๋‹ˆํ„ฐ๋ง์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.
  • ๊ทธ๋Ÿฌ๋‚˜ ์ปจํ…Œ์ด๋„ˆ๋ผ๋Š” ํ™˜๊ฒฝ์—์„œ๋Š” ๊ธฐ์กด ๋ชจ๋‹ˆํ„ฐ๋ง ๋„๊ตฌ๋กœ๋Š” container ๋ชจ๋‹ˆํ„ฐ๋ง ์ง„ํ–‰์ด ์–ด๋ ต์Šต๋‹ˆ๋‹ค.
  • ์ด๋Ÿฌํ•œ ๋ฌธ์ œ์ ์„ ํ•ด๊ฒฐํ•˜๊ณ  ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ธฐ ์œ„ํ•œ ๋„๊ตฌ๋กœ ๊ตฌ๊ธ€์—์„œ ์ œ๊ณตํ•˜๋Š” cAdvisor(Container Advisor)๋ฅผ ๋งŽ์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
toby@tobykakao:~$ docker run \
> --volume=/:/rootfs:ro \
> --volume=/var/run:/var/run:rw \
> --volume=/sys:/sys:ro \
> --volume=/var/lib/docker/:/var/lib/docker:ro \
> --publish=9559:8080 \
> --detach=true \
> --name=cadvisor \
> google/cadvisor:latest
Unable to find image 'google/cadvisor:latest' locally
latest: Pulling from google/cadvisor
ff3a5c916c92: Pull complete 
44a45bb65cdf: Pull complete 
0bbe1a2fe2a6: Pull complete 
Digest: sha256:815386ebbe9a3490f38785ab11bda34ec8dacf4634af77b8912832d4f85dca04
Status: Downloaded newer image for google/cadvisor:latest
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
3c7f1ebd39ec1a4a66e9c4d204c7fadf40dd79d8bdc8356d133e53fad693a46a
toby@tobykakao:~$ docker ps

CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS                          NAMES
08878e469965   google/cadvisor:latest   "/usr/bin/cadvisor -..."   38 seconds ago   Up 37 seconds   0.0.0.0:9559->8080/tcp        cadvisor

์›น ์„œ๋น„์Šค ์‹คํ–‰์„ ์œ„ํ•œ Ngnix ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ ์˜ˆ์ œ

Ngnix ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ ์‹ค์Šต์„ ํ•œ๋ฒˆ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

# Nginx ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œ
toby@tobykakao:~$ docker pull nginx:1.18
1.18: Pulling from library/nginx
15cb40b9c4df: Pull complete 
f54db86c19cf: Pull complete 
da53e28db95d: Pull complete 
6d4f0a6cbe0d: Pull complete 
2d9307d825c8: Pull complete 
Digest: sha256:e90ac5331fe095cea01b121a3627174b2e33e06e83720e9a934c7b8ccc9c55a0
Status: Downloaded newer image for nginx:1.18
docker.io/library/nginx:1.18

# ์ด๋ฏธ์ง€ ํ™•์ธ
toby@tobykakao:~$ docker images
REPOSITORY              TAG       IMAGE ID       CREATED        SIZE
mysql8                  1.0       257c7d00682b   4 days ago     618MB
debian                  latest    d36fff645336   2 weeks ago    139MB
mysql                   8         07b15f39a8d0   2 weeks ago    600MB
mysql                   8.0       e5b1f8113899   2 weeks ago    608MB
nginx                   latest    048e09038596   4 weeks ago    197MB
busybox                 latest    63cd0d5fb10d   5 weeks ago    4.04MB
daehyunbigbread/httpd   3.0       721aa0022a96   3 months ago   178MB
debian-httpd            2.0       721aa0022a96   3 months ago   178MB
httpd                   latest    721aa0022a96   3 months ago   178MB
ubuntu                  14.04     55b7b4f7c5d6   2 years ago    187MB
centos                  8         e6a0117ec169   3 years ago    272MB
nginx                   1.18      9b05b72dd160   3 years ago    126MB
google/cadvisor         latest    eb1210707573   5 years ago    69.6MB

# Nginx ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰. ํ•˜๋‚˜์˜ Nginx ์„œ๋ฒ„ ๊ตฌ๋™์œผ๋กœ ๋ณด๋ฉด ๋จ.
toby@tobykakao:~$ docker run --name webserver1 -d -p 8001:80 nginx:1.18
4185646d8fc886a5be5eabef950bd64553a61058a57c8f2900343b8be99b9d7f
  • -d : ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์‹คํ–‰
  • --name : ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ ์ง€์ •
  • -p : ํ˜ธ์ŠคํŠธ ํฌํŠธ์™€ ์ปจํ…Œ์ด๋„ˆ ํฌํŠธ ๋งคํ•‘ (ํ˜ธ์ŠคํŠธ 8001 ํฌํŠธ๋ฅผ ์ปจํ…Œ์ด๋„ˆ์˜ 80 ํฌํŠธ๋กœ ์—ฐ๊ฒฐ)
# ์ปจํ…Œ์ด๋„ˆ ์ƒํƒœ ํ™•์ธ
toby@tobykakao:~$ docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS          PORTS                                     NAMES
4185646d8fc8   nginx:1.18   "/docker-entrypoint.\u2026"   19 seconds ago   Up 19 seconds   0.0.0.0:8001->80/tcp, [::]:8001->80/tcp   webserver1

# ํ˜ธ์ŠคํŠธ์˜ 8001 ํฌํŠธ๊ฐ€ ์—ด๋ฆฐ ๊ฒƒ์„ ํ™•์ธ
toby@tobykakao:~$ sudo netstat -nlp | grep 8001
tcp        0      0 0.0.0.0:8001            0.0.0.0:*               LISTEN      3879/docker-proxy   
tcp6       0      0 :::8001                 :::*                    LISTEN      3894/docker-proxy 

# ์ ‘์† ํ…Œ์ŠคํŠธ
toby@tobykakao:~$ curl localhost:8001
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

# ์ปจํ…Œ์ด๋„ˆ์˜ ๋ฆฌ์†Œ์Šค ์‚ฌ์šฉ๋Ÿ‰ ์‹ค์‹œ๊ฐ„ ํ™•์ธ
toby@tobykakao:~$ docker stats webserver1
CONTAINER ID   NAME         CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O     PIDS
4185646d8fc8   webserver1   0.00%     1.961MiB / 3.811GiB   0.05%     4.15kB / 1.27kB   0B / 20.5kB   2

# ์ปจํ…Œ์ด๋„ˆ์˜ ์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ์„ธ์Šค ํ‘œ์‹œ
toby@tobykakao:~$ docker top webserver1
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                3936                3916                0                   11:52               ?                   00:00:00            nginx: master process nginx -g daemon off;
message+            3982                3936                0                   11:52               ?                   00:00:00            nginx: worker process


# ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์˜ ์ ‘๊ทผ ๋กœ๊ทธ๋ฅผ ์‹ค์‹œ๊ฐ„ ํ™•์ธ (-f: ์‹ค์‹œ๊ฐ„, -t: ๋งˆ์ง€๋ง‰ ๋กœ๊ทธ๊นŒ์ง€).
$ docker logs -f webserver1
192.168.56.1 - - [01/Mar/2021:07:00:57 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36" "-"
...

# ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ •์ง€ํ•œ๋‹ค. (docker stop -t 10 webserver1, ์˜ต์…˜์€ 10์ดˆ ํ›„ ์ •์ง€)
@tobykakao:~$ docker stop webserver1
webserver1

# ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ค‘์ง€๋จ ํ™•์ธ.
toby@tobykakao:~$ curl localhost:8001
curl: (7) Failed to connect to localhost port 8001 after 0 ms: Couldn't connect to server
# ์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘.
toby@tobykakao:~$ docker start webserver1
webserver1

# ์ ‘์† ํ™•์ธ
toby@tobykakao:~$ curl localhost:8001
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

# Docker๊ฐ€ ์„ค์น˜๋œ host์˜ ip ํ™•์ธ, ์•ž์— ์žˆ๋Š” ์ฃผ์†Œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋จ
toby@tobykakao:~$ hostname -I
192.168.64.7 172.17.0.1 fdaa:7355:ced7:d2ee:e1bb:425a:89e1:b26b fdaa:7355:ced7:d2ee:809b:7cff:fe76:af3b 


# ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์ด์šฉํ•œ ์ ‘๊ทผ ์‹œ๋„, ์ด ์ฃผ์†Œ๋ฅผ ์›นํŽ˜์ด์ง€์— ์ž…๋ ฅํ•˜๋ฉด ๋จ.
http://[๋„์ปค๊ฐ€ ์„ค์น˜๋œ ํ˜ธ์ŠคํŠธ์˜ IP]:8001/

# ์„œ๋ฒ„ ์ฃผ์†Œ ํ™•์ธ (๊ตฌ๋™ ํ™•์ธ ๋ชฉ์ )
toby@tobykakao:~$ curl http://192.168.64.7:8001/
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
# nginx์˜ index.html ๋‚ด์šฉ์„ ๋ณ€๊ฒฝํ•˜์—ฌ ํ…Œ์ŠคํŠธํ•ด ๋ณด์ž.
$ vi index.html
<h1> Hello, Jpub Docker. </h1>

# ๋„์ปค cp ๋ช…๋ น์„ ํ†ตํ•ด ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€ index.html ํŒŒ์ผ ๊ฒฝ๋กœ์— ๋ณต์‚ฌํ•œ๋‹ค.
toby@tobykakao:~$ docker cp index.html webserver1:/usr/share/nginx/html/index.html
Successfully copied 2.05kB to webserver1:/usr/share/nginx/html/index.html

# curl๋กœ ๋ณ€๊ฒฝ๋œ ๋‚ด์šฉ ํ™•์ธ
toby@tobykakao:~$ curl localhost:8001
<h1> Hello, Kakao Docker. </h1>

# ์—ฐ๊ฒฐ๋œ ๋ธŒ๋ผ์šฐ์ €์—์„œ [F5]๋ฅผ ๋ˆŒ๋Ÿฌ ์ƒˆ๋กœ๊ณ ์นจ ํ•œ๋‹ค.

curl๋กœ container index.html ๋ณ€๊ฒฝ๋œ ํŽ˜์ด์ง€


Docker Container์˜ ์ผ์‹œ์ •์ง€(pause), ์ผ์‹œ์ •์ง€ ํ•ด์ œ(unpause), ์žฌ์‹œ์ž‘(restart)์‚ฌ์šฉ

docker pause ๋ช…๋ น์€ ์ง€์ •๋œ ์ปจํ…Œ์ด๋„ˆ์˜ ๋ชจ๋“  ํ”„๋กœ์„ธ์Šค๋ฅผ ์ผ์‹œ ์ค‘๋‹จํ•ฉ๋‹ˆ๋‹ค. ๋ฆฌ๋ˆ…์Šค์—์„œ๋Š” freezer cgroup์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
# ํ”„๋กœ์„ธ์Šค๋ฅผ ์ผ์‹œ ์ค‘์ง€ํ•  ๋•Œ SIGSTOP ์‹ ํ˜ธ๊ฐ€ ์‚ฌ์šฉ๋œ๋‹ค.
toby@tobykakao:~$ docker pause webserver1
webserver1

# ์ปจํ…Œ์ด๋„ˆ ์ƒํƒœ ํ™•์ธ (Paused ์ƒํƒœ๋กœ ํ‘œ์‹œ๋จ)
toby@tobykakao:~$ docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS                   PORTS                                     NAMES
4185646d8fc8   nginx:1.18   "/docker-entrypoint.\u2026"   21 minutes ago   Up 14 minutes (Paused)   0.0.0.0:8001->80/tcp, [::]:8001->80/tcp   webserver1

# docker unpause ๋ช…๋ น์€ ์ง€์ •๋œ ์ปจํ…Œ์ด๋„ˆ์˜ ๋ชจ๋“  ํ”„๋กœ์„ธ์Šค์—์„œ ์ผ์‹œ ์ค‘๋‹จ์„ ํ•ด์ œํ•œ๋‹ค.
toby@tobykakao:~$ docker unpause webserver1
webserver1

# ์ปจํ…Œ์ด๋„ˆ ์ƒํƒœ ํ™•์ธ (Paused ์ƒํƒœ ํ•ด์ œ๋จ)
toby@tobykakao:~$ docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED          STATUS          PORTS                                     NAMES
4185646d8fc8   nginx:1.18   "/docker-entrypoint.\u2026"   21 minutes ago   Up 15 minutes   0.0.0.0:8001->80/tcp, [::]:8001->80/tcp   webserver1
  • ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์žฌ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์€ ๊ธฐ์กด ์ปจํ…Œ์ด๋„ˆ์˜ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ •์ง€ํ•˜๊ณ  ์ƒˆ๋กœ์šด ์ปจํ…Œ์ด๋„ˆ ํ”„๋กœ์„ธ์Šค๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
  • ์ปจํ…Œ์ด๋„ˆ ๋™์ž‘์—๋Š” ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๊ณ , ํ˜ธ์ŠคํŠธ์˜ ํ”„๋กœ๋งŒ ๋ณ€๊ฒฝ๋ฉ๋‹ˆ๋‹ค.
# (8001์€ ์œ„ ์‹ค์Šต์—์„œ nginx์˜ ํ˜ธ์ŠคํŠธ ์—ฐ๊ฒฐ ํฌํŠธ๋ฅผ ์‚ฌ์šฉ)
toby@tobykakao:~$ ps -ef | grep 8001
root        4946    1175  0 11:59 ?        00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8001 -container-ip 172.17.0.2 -container-port 80
root        4958    1175  0 11:59 ?        00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8001 -container-ip 172.17.0.2 -container-port 80
toby        5681    4796 50 12:16 pts/0    00:00:00 grep --color=auto 8001

# ์ปจํ…Œ์ด๋„ˆ ์žฌ์‹œ์ž‘
toby@tobykakao:~$ docker restart webserver1
webserver1

# ์žฌ์‹œ์ž‘ ํ›„ ํ™•์ธ
toby@tobykakao:~$ ps -ef | grep 8001
root        5753    1175  0 12:16 ?        00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8001 -container-ip 172.17.0.2 -container-port 80
root        5760    1175  0 12:16 ?        00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8001 -container-ip 172.17.0.2 -container-port 80
toby        5843    4796  0 12:16 pts/0    00:00:00 grep --color=auto 8001