๐Ÿ‘ฉโ€๐Ÿ’ป0708[docker]

๋ง์ง€ยท2022๋…„ 7์›” 8์ผ
0

๐Ÿ“Œ DOCKER - ์ด๋ก 

โœ”๏ธ ๋„์ปค๊ฐ€ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์•„๋‹ˆ๊ณ  ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ด๋ฏธ ์žˆ์—ˆ๊ณ . ์ปจํ…Œ์ด๋„ˆ๋กœ ๋ณ„๋„์˜ ๊ณต๊ฐ„์„ ๋งŒ๋“ค์–ด์„œ (VM์ฒ˜๋Ÿผ) ๊ฐ€์ƒํ™” ๊ธฐ์ˆ  ์‚ฌ์šฉ. - ์šด์˜์ฒด์ œ ์ˆ˜์ค€ ๊ฐ€์ƒํ™”.

โœ”๏ธ ๊ฐ€์ƒํ™”๊ธฐ์ˆ  (type2)์™€ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ์ˆ  ๋น„๊ต

์ด์ง„ ; ์‹คํ–‰ ํŒŒ์ผ

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

์ปจํ…Œ์ด๋„ˆ์—๋Š” ์˜ค์—์Šค๊ฐ€ ์—†์ง€์ง€๋งŒ ํ˜ธ์ŠคํŠธ OS ์˜ ๊ธฐ๋Šฅ์„ ๋„์ปค๊ฐ€ ์ปจํ…Œ์ด๋„ˆ์—๊ฒŒ ์ „๋‹ฌ. -> ์˜ค์—์Šค๊ฐ€ ์—†์–ด์„œ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์—†๋‹ค. ๊ทธ๋ž˜์„œ ์šด์˜์ฒด์ œ ์ˆ˜์ค€ ๊ฐ€์ƒํ™”.

โœ”๏ธ ์ด๋ฏธ์ง€๊ฐ€ ๋จผ์ €๋‹ค !

โœ”๏ธ ํฌํŠธํฌ์›Œ๋“œ

โœ”๏ธ life cycle

๐Ÿ“Œ DOCKER - ์‹ค์Šต

๐Ÿ“™ ํ˜ธ์ŠคํŠธ OS ๋งŒ๋“ค๊ธฐ ( ์ค‘์ฒฉ๋œ ๊ฐ€์ƒํ™” )

ํ˜ธ์ŠคํŠธ OS๋ฅผ VM์œผ๋กœ ์ƒ์„ฑ - > ์ค‘์ฒฉ๋œ ๊ฐ€์ƒํ™”๋กœ ์ง„ํ–‰
โœ”๏ธ ํ˜ธ์ŠคํŠธ OS๋กœ ์‚ฌ์šฉํ•  ova(centos)๊ฐ€์ ธ์˜ค๊ธฐ

โœ”๏ธ ์ด๋ฆ„ DOCKER๋กœ ๋ฐ”๊ฟ”์ฃผ๊ณ  ์„ค์ •- ๋„คํŠธ์›Œํฌ์—์„œ ๋ธŒ๋ฆฟ์ง€ ํ™•์ธํ•˜๊ณ  ์‹คํ–‰

โœ”๏ธ IPํ™•์ธํ•˜๊ณ  ์ด์ „ ansible server์™€ ip ๊ฐ™์€ ๊ฒฝ์šฐ ์„œ๋ฒ„ ์ „์› ๋„๊ณ  ์„ค์ •- ๋„คํŠธ์›Œํฌ - ์–ด๋Œ‘ํ„ฐ 1 - ๊ณ ๊ธ‰ - MAC์ฃผ์†Œ ๋ฐ”๊ฟ”์ฃผ๊ธฐ


์ƒˆ IP : 192.168.1.91

โœ”๏ธmobaxterm์œผ๋กœ ์ง„ํ–‰ํ•˜์—ฌ ์‹ค์Šต ์ง„ํ–‰

๐Ÿ“™์„ผํ† ์Šค ๋„์ปค ์„ค์น˜

DOCKER CE; Community Edition ๋ฌด๋ฃŒ ์˜คํ”ˆ ์†Œ์Šค, EE; Enterprise Edition ์œ ๋ฃŒ, ๋ณด์•ˆ ๊ด€๋ จ ์ทจ์•ฝ์  ์ ๊ฒ€ ์„œ๋น„์Šค ์ œ๊ณต )

# curl -fsSL https://get.docker.com/ | sh //์ตœ์‹ ์˜ ๋„์ปค ์„ค์น˜
# yum -y install bash-completion wget unzip net-tools mysql telnet rdate
# rdate -s time.bora.net && clock -w
# curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o /etc/bash_completion.d/docker.sh
# systemctl enable --now docker
[root@localhost ~]# docker --version
Docker version 20.10.17, build 100c701

-> ์…‹ํŒ… ์™„๋ฃŒ. ์ด์ œ๋ถ€ํ„ฐ๋Š” ๋„์ปค ์—”์ง„ or ๋„์ปค ํ˜ธ์ŠคํŠธ๋ผ๊ณ  ๋ถ€๋ฅผ ์ˆ˜ ์žˆ์Œ.

๐Ÿ“™ ๋„์ปค ๊ธฐ๋ณธ ๋ช…๋ น์–ด

โœ”๏ธ ๋„์ปค ์ด๋ฏธ์ง€ ๋‹ค์šด๋กœ๋“œ, ๊ฒ€์ƒ‰ ์‚ฌ์ดํŠธ
https://hub.docker.com/
์šด์˜์ฒด์ œ์™€ ์œ ์‚ฌํ•œ ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰ ๊ฐ€๋Šฅ. (์ปค๋„์ด ์žˆ๋Š” ๋™์ผํ•œ ๊ฒƒ์€ ์•„๋‹˜)

# docker search nginx //nginx ์ด๋ฏธ์ง€ ๊ฒ€์ƒ‰
# docker image pull nginx //nginx ์ด๋ฏธ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ
# docker image ls
# docker image ls -q //์ด๋ฏธ์ง€๋งŒ
# docker image inspect --format="{{ .Os}}" nginx // key value ์ด์šฉํ•˜์—ฌ ๊ฒ€์ƒ‰(ํ•„ํ„ฐ๋ง); nginx์˜ OS ํ™•์ธ
# docker container create -p 80:80 --name webserver nginx 
// ํฌํŠธํฌ์›Œ๋“œ ์™ผ์ชฝ(ํ˜ธ์ŠคํŠธ):์˜ค๋ฅธ์ชฝ(์ปจํ…Œ์ด๋„ˆ) 
// -p; publish 
// --name; ์ปจํ…Œ์ด๋„ˆ์— ์ด๋ฆ„ ์ฃผ๊ธฐ

[root@localhost ~]# docker container ls -a
// created ์ƒํƒœ์ธ container์˜ ์ •๋ณด ๋ณด๋ ค๋ฉด '-a'๋ถ™์—ฌ์•ผํ•จ.
// ์•„์ง ์‹คํ–‰๋˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— -a๋ฅผ ๋ˆ„๋ฝํ•˜๋ฉด ์ •๋ณด ์•ˆ๋ณด์ž„.


# docker container start webserver
[root@localhost ~]# docker container ls

-> ์›น ๋ธŒ๋ผ์šฐ์ €์—์„œ http://192.168.1.91/ (๋„์ปค ํ˜ธ์ŠคํŠธ IP)
์ง„์ž…ํ•˜์—ฌ ์›น์„œ๋ฒ„ ๊ฐ€๋ณด๊ธฐ.

โœ”๏ธ run์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ ์›น์„œ๋ฒ„ ์ƒ์„ฑ

# docker container stop webserver 
# docker container ls -a //์„œ๋ฒ„ ๋ฉˆ์ถ”๋ฉด(exited) ls๋งŒ ํ•˜๋ฉด ์•ˆ๋‚˜์˜ด. -a ๊ผญ ๋ถ™์—ฌ์•ผํ•จ.
# docker container start webserver
# docker container rm -f webserver // ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ๋Š” -f ๋ถ™์—ฌ์„œ ์ง€์›Œ์•ผํ•จ.
# docker container run -p 80:80 --name webserver nginx 
//create + start -> host IP๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅ
//foreground์‹คํ–‰์ด๋ผ ์ด๊ฑฐ ํ•˜๋ฉด์„œ ๋‹ค๋ฅธ ๊ฑฐ๋ชปํ•จ. ์ปจํŠธ๋กค ์”จ๋กœ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๋Š”๋ฐ, ๊ทธ๋Ÿฌ๋ฉด ์„œ๋ฒ„ ์ค‘์ง€๋จ.
# docker container rm webserver //์ง€์› ๋‹ค๊ฐ€ background๋กœ ๋‹ค์‹œ๋งŒ๋“ค๊ธฐ.
# docker container run -d -p 80:80 --name webserver nginx 
// -d ; background ์‹คํ–‰
//์‹คํ–‰๊ณผ ๋™์‹œ์— ๋‹ค๋ฅธ๊ฑฐ ํ•  ์ˆ˜ ์žˆ์Œ.

โœ”๏ธ ์„œ๋ฒ„ ์ƒ์„ฑ ์ถฉ๋Œ๋‚˜๋Š” ๊ฒฝ์šฐ

# docker container run -d -p 81:80 --name webserver nginx // ์ด๋ฆ„ ์ถฉ๋Œ - ์ƒ์„ฑ ์•ˆ๋จ . ๋งŒ๋“ค์–ด์ง€์ง€ ์•Š์Œ.
# docker container run -d -p 81:80 --name webserver2 nginx //์ •์ƒ ์ƒ์„ฑ
# docker container run -d -p 81:80 --name webserver3 nginx 
// ํฌํŠธ๋ฒˆํ˜ธ ์ถฉ๋Œ- ์˜ค๋ฅ˜๋‚ฌ์ง€๋งŒ ์ปจํ…Œ์ด๋„ˆ๋Š” ๋งŒ๋“ค์–ด์ง. (๋ฉˆ์ถ”์–ด์ ธ ์žˆ๋Š” ์ƒํƒœ)
# docker container run -d -p 82:80 --name webserver3 nginx // ์œ„์—์„œ ์˜ค๋ฅ˜๋‚ฌ์ง€๋งŒ ๋งŒ๋“ค์–ด์ ธ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฆ„ ์ถฉ๋Œ๋กœ ๋งŒ๋“ค์–ด์ง€์ง€ ์•Š์Œ. 
# docker container rm -f webserver3 //์‚ญ์ œ
# docker container run -d -p 82:80 --name webserver3 nginx //๋‹ค์‹œ ํฌํŠธ๋ฒˆํ˜ธ์™€ ์ด๋ฆ„ ์ค‘๋ณต๋˜์ง€ ์•Š๊ฒŒ๋งŒ๋“ค๋ฉด ์™„๋ฃŒ.


# docker container ls -a

โœ”๏ธ /bin/cal ์บ˜๋ฆฐ๋” ์‚ฌ์šฉ

[root@localhost ~]# /bin/cal
      July 2022
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
// ๋„์ปค ํ˜ธ์ŠคํŠธ ์„œ๋ฒ„์—์„œ /bin/cal ์‹คํ–‰.

# docker container run --name test_cal centos /bin/cal 
//centos์ด๋ฏธ์ง€ ์ด์šฉํ•ด์„œ /bin/cal ์ด์šฉ(๋ช…๋ น์–ด or ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜)ํ•ด์„œ output ํ•  ์ˆ˜ ์žˆ๋Š” ์ปจํ…Œ์ด๋„ˆ ์ œ์ž‘
//์•„์ฃผ ์ผ์‹œ์ ์ด๊ณ  ํ•œ์‹œ์ ์ธ ์ปจํ…Œ์ด๋„ˆ ์ œ์ž‘. /bin/cal ๊ธฐ๋Šฅ ์ž ์‹œ ์ˆ˜ํ–‰ํ•˜๊ณ  ๋ฉˆ์ถœ ๊ฒƒ.

Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
      July 2022
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

// ๋„์ปค ํ˜ธ์ŠคํŠธ์—์„œ ๋งŒ๋“  ์ปจํ…Œ์ด๋„ˆ(centos)์—์„œ ๋ช…๋ น์–ด ์ด์šฉํ•ด์„œ ์บ˜๋ฆฐ๋” ์ถœ๋ ฅ.

โœ”๏ธ ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑํ•˜๊ณ  ๋‚ด๋ถ€๋กœ ๋ฐ”๋กœ ์ง„์ž…ํ•˜๊ธฐ.; '-it' ์ค‘์š”@@@โญ๏ธโญ๏ธโญ๏ธโญ๏ธโญ๏ธ


# docker container run -it --name test_bash centos /bin/bash
// -it ์ปจํ…Œ์ด๋„ˆ์— ๋ฐ”๋กœ ์ง„์ž…(ํ„ฐ๋ฏธ๋„)ํ•˜๋Š” ์˜ต์…˜ (ssh reomote ์ ‘์†์ด๋ž‘ ๋น„์Šท)
exit

โœ”๏ธ ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์‹คํ–‰ ; '-d'์ค‘์š”@@@ โญ๏ธโญ๏ธโญ๏ธโญ๏ธ


# docker container run -d --name test_ping centos /bin/ping localhost //-d ;detattch, background ์‹คํ–‰
[root@localhost ~]# docker container ls
CONTAINER ID   IMAGE     COMMAND                  CREATED              STATUS              PORTS                               NAMES
6fcf9bd99a8a   centos    "/bin/ping localhost"    About a minute ago   Up About a minute                                       test_ping
// -a ์—†์ด ํ™•์ธ ๊ฐ€๋Šฅ.

# docker container logs -t test_ping
// ping ๋‚˜๊ฐ€๋Š”๊ฑฐ ์‹ค์‹œ๊ฐ„์œผ๋กœ ํ™•์ธ. ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์ผ์–ด๋‚˜๋Š” ๋กœ๊ทธ๋‚˜ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๋Š” ๋ช…๋ น์–ด

โœ”๏ธ์ปจํ…Œ์ด๋„ˆ ๋ฆฌ์†Œ์Šค ์ง€์ •


# docker container run -d -p 8080:80 --name test_port nginx 
//๋งˆ์ง€๋ง‰ nginx์ด๋ฆ„์€ ์ด๋ฏธ์ง€ ์ด๋ฆ„. 

# docker container stats test_port
//cpu,ram์ƒํƒœ๋ณด๊ธฐ

# docker container run -d -p 8181:80 --cpus 1 --memory=256m --name test_resource nginx // CPU,RAM ์ง€์ •ํ•ด์„œ ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑ. ํ˜ธ์ŠคํŠธ๋ฅผ ์ดˆ๊ณผํ•˜๋Š” ์ž์›์„ ์ •ํ•˜๋ฉด ์—๋Ÿฌ๊ฐ€ ๋‚จ. ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ํ˜ธ์ŠคํŠธ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ชจ๋“  ์ž์›์„ ์ด์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•จ.

โœ”๏ธ ์ปจํ…Œ์ด๋„ˆ ๋””๋ ‰ํ† ๋ฆฌ ๊ณต์œ  ; '-v' ์ค‘์š”!! โญ๏ธโญ๏ธโญ๏ธ

# docker container run -d -p 8282:80 --cpus 1 --memory=256m -v /tmp:/usr/share/nginx/html --name volume-container nginx 
//-v; bind mount 
[root@localhost ~]# cd /tmp
[root@localhost tmp]# ls
ks-script-fkKyI6  yum.log
[root@localhost tmp]# echo "hello world" > index.html
[root@localhost tmp]# ls
index.html  ks-script-fkKyI6  yum.log


-> tmp์™€ nginx html ํด๋”๊ฐ€ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์–ด ๋ฐ”๋กœ ์›น์„œ๋ฒ„ ํŒŒ์ผ ๋ฐ”๊ฟ”์ค„ ์ˆ˜ ์žˆ์Œ.

โœ”๏ธ ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก ํ™•์ธํ•˜๊ธฐ + ํ•„ํ„ฐ๋ง ๊ฒ€์ƒ‰

# docker container ls
# docker container ls -a
# docker container ls -a -f name=test_webserver // ์ด๋ฆ„์œผ๋กœ ๊ฒ€์ƒ‰ํ•˜๊ธฐ
# docker container ls -a -f name=test_ // ์ค‘๊ฐ„์–ด ๊ฒ€์ƒ‰๋„ ๋จ.
# docker container ls -a -f exited=0 // ๋ฉˆ์ถฐ(์ค‘์ง€)์žˆ๋Š” ๊ฒƒ๋“ค๋งŒ ๋ณด๊ธฐ 
# docker container ls -a --format "table {{.Names}}\t{{.Status}}" //์ด๋ฆ„์ด๋ž‘ ์ƒํƒœ๋งŒ ๋ณด๊ธฐ

โœ”๏ธ ๋™์ž‘์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ์—ฐ๊ฒฐ

# docker container start  test_bash
# docker container attach test_bash
[root@1689b6318c35 /]# ctrl + p, ctrl +q ๋ฅผ ์ž…๋ ฅ
# docker container ls
//exit๋กœ ๋‚˜์˜ค๋ฉด ์ปจํ…Œ์ด๋„ˆ๊ฐ€ exited์ƒํƒœ๊ฐ€ ๋จ (๋‹ค์šด) ์œ„ ํ‚ค๋ณด๋“œ ํ‚ค๋กœ ๋ˆ„๋ฅด๊ณ  ๋‚˜์˜ค๋ฉด ์‹คํ–‰ ๋œ ์ƒํƒœ์—์„œ ๋„์ปคํ˜ธ์ŠคํŠธ๋กœ ๋‚˜์˜ค๊ธฐ ๊ฐ€๋Šฅ.

โœ”๏ธ ๋™์ž‘์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ์—์„œ ํ”„๋กœ์„ธ์Šค ์‹คํ–‰

# docker contianer exec [์˜ต์…˜]<์ปจํ…Œ์ด๋„ˆ><์‹คํ–‰๋ช…๋ น>[์ธ์ˆ˜]
# docker container exec -it test_port /bin/echo "Hello world"
//์ปจํ…Œ์ด๋„ˆ ์•ˆ์œผ๋กœ ๋“ค์–ด๊ฐ€์„œ echo์ด์šฉํ•ด์„œ hello world ์ถœ๋ ฅ
# docker container exec -it test_port /bin/bash
//exit๋กœ ๋‚˜์™€๋„ ์ปจํ…Œ์ด๋„ˆ exited ๋˜์ง€ ์•Š์Œ.
// ๊ฒฝ๋กœ /bin/bash	์ธ๊ฒŒ ์ค‘์š”. ์ด ๋ช…๋ น์–ด๊ธฐ ๋•Œ๋ฌธ์— ๋‚ด๋ถ€๋กœ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ์Œ.
//๋งŒ์•ฝ /bin/cal ์ด์—ˆ์œผ๋ฉด ์บ˜๋ฆฐ๋”๋งŒ ์ถœ๋ ฅํ•ด์ฃผ๊ณ  ๋.
//์š” ๋ผ์ธ์€ ํ†ต์œผ๋กœ ๊ธฐ์–ตํ•˜์ž!

์‘์šฉ /bin/bash๋กœ ์›น์„œ๋ฒ„ ํ™”๋ฉด ๋ฐ”๊พธ๊ธฐโญ๏ธโญ๏ธโญ๏ธโญ๏ธโญ๏ธ

[root@localhost ~]# docker container exec -it webserver /bin/bash
root@2ac073800eed:/#
root@2ac073800eed:/# cd /usr/share/nginx/html
root@2ac073800eed:/usr/share/nginx/html# ls
50x.html  index.html
root@2ac073800eed:/usr/share/nginx/html#
root@2ac073800eed:/usr/share/nginx/html# echo "aloha" > index.html

โœ”๏ธ ๋™์ž‘์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ํ”„๋กœ์„ธ์Šค ํ™•์ธ


# docker container top test_port // ์ปจํ…Œ์ด๋„ˆ์— ์‹คํ–‰์ค‘์ด ํ”„๋กœ์„ธ์Šค๋“ค ํ™•์ธ

โœ”๏ธ ๋™์ž‘์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ์˜ ํฌํŠธ ์ „์†ก ํ™•์ธ

# docker container port test_port

โœ”๏ธ ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ ๋ฐ”๊พธ๊ธฐโญ๏ธ

# docker container rename test_port webserver10

โœ”๏ธ ์ปจํ…Œ์ด๋„ˆ ์•ˆ์˜ ํŒŒ์ผ ๋ณต์‚ฌโญ๏ธโญ๏ธโญ๏ธโญ๏ธ

# docker container cp webserver:/usr/share/nginx/html/index.html /root/index.html
// ์™ผ์ชฝ ์ปจํ…Œ์ด๋„ˆ ๊ฒฝ๋กœ ์—์„œ ์˜ค๋ฅธ์ชฝ ํ˜ธ์ŠคํŠธ ๊ฒฝ๋กœ๋กœ ๊ฐ€์ ธ์˜ค๊ธฐ
[root@localhost ~]# cd ~
[root@localhost ~]# ls
anaconda-ks.cfg  index.html
[root@localhost ~]# vi index.html
aloha
Ohayo

# docker container cp ./index.html webserver:/usr/share/nginx/html/index.html

->๊ฒฐ๊ณผ ํ™•์ธ

โœ”๏ธ์ปจํ…Œ์ด๋„ˆ ์•ˆ์˜ ํŒŒ์ผ ๋ณต์‚ฌ 2
aws.tarํŒŒ์ผ ๋„์ปคํ˜ธ์ŠคํŠธ ์„œ๋ฒ„์˜ home๋””๋ ‰ํ† ๋ฆฌ์— ๋ชจ๋ฐ”์—‘์Šคํ…€์œผ๋กœ ๋„ฃ์–ด๋‘๊ธฐ.

[root@localhost ~]# mkdir html
[root@localhost ~]# tar -xvf aws.tar -C ./html/
[root@localhost ~]# docker container cp ./html webserver:/usr/share/nginx

-> ๊ฒฐ๊ณผ

โœ”๏ธ ์ปจํ…Œ์ด๋„ˆ์™€ ์›๋ณธ ์ด๋ฏธ์ง€์˜ ์ฐจ์ด์  ํ™•์ธ


# docker container diff webserver //๋ณ€๊ฒฝ์‚ฌํ•ญ ํ™•์ธ. ๋ณด์•ˆ์ ์ธ ์ธก๋ฉด.

โœ”๏ธ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ด๋ฏธ์ง€๋กœ ๋งŒ๋“ค๊ธฐ (์Šค๋ƒ…์ƒท๊ฐ™์€ ๋Š๋‚Œ)โญ๏ธโญ๏ธโญ๏ธโญ๏ธโญ๏ธโญ๏ธ

# docker container commit -a "johnlee<test@example.com>" -m "NICE TO MEET YOU" webserver test_commit:v1.0
//-a; author.  ์ž‘์„ฑ์ž ์ด๋ฆ„ -> ์„ ํƒ์‚ฌํ•ญ
//-m ; message. -> ์„ ํƒ์‚ฌํ•ญ
//webserver ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„
// test_commit ์ด๋ฏธ์ง€ ์ด๋ฆ„ 
// :v1.0  ํƒœ๊ทธ

[root@localhost ~]# docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
test_commit   v1.0      092d1ba32297   13 seconds ago   143MB

โœ”๏ธ ์œ„์—์„œ ๋งŒ๋“  ์ด๋ฏธ์ง€ ๋ฐ›์„ ์„œ๋ฒ„ ๋งŒ๋“ค๊ธฐ

์šฐ๋ถ„ํˆฌ 18 ์‹คํ–‰ ( ubuntu-node01) ํ›„ ๋ชจ๋ฐ”์—‘์Šคํ…€ ์ง„์ž…ํ•˜์—ฌ ์•„๋ž˜ ๋ช…๋ น์–ด ์ง„ํ–‰. ( ์šฐ๋ถ„ํˆฌ ๋„์ปค ์„ค์น˜ )

$ apt update
$ sudo apt install apt-transport-https ca-certificates curl software-properties-common -y 
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
$ sudo apt update
$ sudo apt-cache policy docker-ce
$ sudo apt install docker-ce -y

โœ”๏ธ ์ด๋ฏธ์ง€ tar ํŒŒ์ผ๋กœ ๋งŒ๋“ค์–ด์„œ ๋ณด๋‚ด๊ธฐ

# docker image inspect test_commit:v1.0
# docker image save -o test_commit.tar test_commit:v1.0
//์ด๋ฏธ์ง€ ๋ณด๋‚ด๊ธฐ ์œ„ํ•ด ํƒ€๋ฅดํŒŒ์ผ๋กœ ๋งŒ๋“ค๊ธฐ. ์ด๋ฏธ์ง€ ์ด๋ฆ„์ด ๋งจ ๋’ค์— ์˜ด.

[root@localhost ~]# ls
anaconda-ks.cfg  aws.tar  html  index.html  test_commit.tar
[root@localhost ~]# scp test_commit.tar root@192.168.1.46:/root

โœ”๏ธ ์ด๋ฏธ์ง€ ๋ฐ›์•„์„œ ์ปจํ…Œ์ด๋„ˆ ๋งŒ๋“ค์–ด๋ณด๊ธฐ

root@ubuntu-node01:~# ls
nfs  test_commit.tar

root@ubuntu-node01:~# docker image load -i test_commit.tar

root@ubuntu-node01:~# docker image ls
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
test_commit   v1.0      092d1ba32297   21 minutes ago   143MB

root@ubuntu-node01:~# docker container run -d -p 80:80 --name webserver test_commit:v1.0

->๊ฒฐ๊ณผ ํ™•์ธ

# docker network ls
# docker network ls -q --filter driver=bridge
# docker network create -d bridge --subnet 192.168.123.0/24 --ip-range 192.168.123.0/24 test_bridge
# docker network rm test_bridge
# docker network connect test_bridge webserver
# docker container inspect webserver
# docker network disconnect test_bridge webserver
# docker container run -d --name webserver1 --network test_bridge -p 8080:80 nginx
# docker network inspect test_bridge

๐Ÿ“™โœ”๏ธโœ๏ธ๐Ÿ“ขโญ๏ธ๐Ÿ“Œ

๐Ÿ“Œ ๊ธฐํƒ€

โญ๏ธ docker inspect ๊ฒ€์ƒ‰ํ•˜๋Š” ๋ฐฉ๋ฒ•


ํ•˜์œ—๋‹จ ๊ฒ€์ƒ‰ํ•˜๋ ค๋ฉด ๊ฒน ์ค‘๊ด„ํ˜ธ ์•ˆ์— .~(์ตœ์ƒ์œ„).@(ํ•˜์œ„) ๋„ฃ์–ด์„œ ๊ฒ€์ƒ‰.


๊ทธ๋žฉ ๋ช…๋ น์–ด๋„ ์‚ฌ์šฉ ๊ฐ€๋Šฅ.

โญ๏ธ docker status

์‹คํ–‰์ค‘(up) - ํ”„๋กœ์„ธ์Šค์— ์˜ฌ๋ผ๊ฐ”๋‹ค.
CPU, ๋ฉ”๋ชจ๋ฆฌ, ๋””์Šคํฌ ์ž์›์„ ์ ์œ .
์ปจํ…Œ์ด๋„ˆ๋Š” ์ผ์ข…์˜ ํ”„๋กœ์„ธ์Šค.
ํ”„๋กœ์„ธ์Šค์— ์˜ฌ๋ผ๊ฐ€๊ธฐ ์ „์—๋Š” ์ •์ ์ธ ์ƒํƒœ๋กœ ๋‚จ์•„์žˆ์–ด์„œ ls ๋ช…๋ น์–ด ์ฃผ๋ฉด ์•ˆ๋‚˜์˜ด. ์‹คํ–‰ ์‹œ์ผœ์•ผ ๋‚˜์˜จ๋‹ค.

โญ๏ธ ๋„์ปค์›น์„œ๋ฒ„์™€ ํฌํŠธํฌ์›Œ๋“œ

๋„์ปค์— ์‚ฌ์šฉ์ž๊ฐ€ ์ ‘๊ทผํ•˜๋ ค๋ฉด ๋„์ปค ํ˜ธ์ŠคํŠธ ip๋กœ(1๊ฐœ) ์ ‘๊ทผํ•ด์•ผํ•จ. ๊ทธ๋ž˜์„œ ์—ฌ๋Ÿฌ ์„œ๋ฒ„๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ ํฌํŠธํฌ์›Œ๋“œ๋ฅผ ํ•ด์ค˜์•ผํ•จ.

โญ๏ธ run

์ด๋ฏธ์ง€ ๊ฐ€์ ธ์˜ค๊ธฐ
container create
container ์‹คํ–‰
์œ„ ๊ธฐ๋Šฅ์„ ๋ชจ๋‘ ๊ฐ€์ง€๊ณ  ์žˆ์Œ. ; pull ํ•„์š”๊ฐ€ ์—†๋‹ค.

โญ๏ธ container ์ด๋ฆ„ ์„ค์ • ์•ˆํ•˜๊ณ  run ์‹คํ–‰์‹œ ์ด๋ฆ„ ์ž„์˜๋กœ ๋ถ€์—ฌ๋จ.

[root@localhost ~]# docker container run centos /bin/cal
[root@localhost ~]# docker container ls -a
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS                      PORTS                               NAMES
5e8ee6cd6a6a   centos    "/bin/cal"               21 seconds ago   Exited (0) 20 seconds ago                                       happy_ellis

profile
๊พธ์ค€ํžˆ, ์ฐจ๊ทผ์ฐจ๊ทผ

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