+ 00 00 0000

Have any Questions?

02_Simple Coding – 01_use_container

02_Simple Coding – 01_use_container

์‰ฌ์šด ๋ชฉ์ฐจ

๐Ÿ“ƒ ์š”์•ฝ

์ปดํ“จํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์ตœ์ดˆ ์œˆ๋„์šฐ๋ฅผ ์„ค์น˜ํ•ด์•ผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ.
์œˆ๋„์šฐ ํ”„๋กœ๊ทธ๋žจ์„ OS(Operating System) ๋ผ๊ณ  ํ•˜๊ณ  ์šด์˜์ฒด์ œ๋ผ๊ณ  ํ•จ.
์šด์˜์ฒด์ œ๋Š” ํ‚ค๋ณด๋“œ, ๋งˆ์šฐ์Šค, ์Œ์•…, ๋™์˜์ƒ ๋“ฑ์˜ ํ™˜๊ฒฝ์„ ์‰ฝ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” S/W ๋กœ ์ตœ์ดˆ๋กœ ์„ค์น˜๋˜์–ด์•ผ ํ•จ.
์šด์˜์ฒด์ œ์˜ ์ข…๋ฅ˜๋Š” ์œˆ๋„์šฐ(Window), ๋ฆฌ๋ˆ…์Šค(Linux), ์œ ๋‹‰์Šค(Unix)๊ฐ€ ์žˆ์œผ๋ฉฐ ์ฃผ๋กœ ๊ฐœ์ธ์šฉ์œผ๋กœ ์œˆ๋„์šฐ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ํšŒ์‚ฌ์—์„œ๋Š” ๋ฆฌ๋ˆ…์Šค ๋˜๋Š” ์œ ๋‹‰์Šค๊ฐ€ ์‚ฌ์šฉ๋จ

์š”์†Œ ๊ธฐ์ˆ  :

– Basic : ๋ฆฌ๋ˆ…์Šค

๐Ÿ“ƒ ๊ธฐ์ˆ  ๊ตฌํ˜„

์ŠคํŽ™ :

- docker desktop

๐Ÿ“ƒ ์ปจํ…Œ์ด๋„ˆ ๋‹ค๋ฃจ๊ธฐ

01) : ์ปจํ…Œ์ด๋„ˆ ๋‹ค๋ฃจ๊ธฐ

02_1) ๋Œ€ํ™”ํ˜• ๋ชจ๋“œ๋กœ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ๋ฐ ์ •์ง€
์‚ฌ์šฉ๋ฒ•) docker run -it ์ด๋ฏธ์ง€๋ช… bash
-it : ๋Œ€ํ™”ํ˜• ๋ชจ๋“œ(ํ„ฐ๋ฏธ๋„)๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์˜ต์…˜
bash : ์…€ ํ™˜๊ฒฝ ์ง€์ •(bash(๋ฐฐ์‰ฌ์…€), sh(๋ณธ์…€))

02) ํ˜„์žฌ ์ „์ฒด ์ปจํ…Œ์ด๋„ˆ์™€ ์ด๋ฏธ์ง€ ์‚ญ์ œํ•˜๊ธฐ

์ „์ฒด ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก ๋ณด๊ธฐ
docker ps -a
C:\Users2>docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
ccf0e618b725        ubuntu              "bash"              17 hours ago        Exited (137) 17 hours ago                       ubuntu

03) ์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œํ•˜๊ธฐ

docker rm ccf0e618b725
C:\Users2>docker rm ccf0e618b725
ccf0e618b725

04) ์ „์ฒด ์ด๋ฏธ์ง€ ๋ณด๊ธฐ

docker images
C:\Users2>docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
kangtaegyung/ubuntu   latest              1f6ddc1b2547        2 weeks ago         77.8MB
ubuntu                latest              1f6ddc1b2547        2 weeks ago         77.8MB

05) ์ด๋ฏธ์ง€(ํƒœ๊ทธ) ์‚ญ์ œํ•˜๊ธฐ

docker rmi kangtaegyung/ubuntu
C:\Users2>docker rmi kangtaegyung/ubuntu
Untagged: kangtaegyung/ubuntu:latest
Untagged: kangtaegyung/ubuntu@sha256:65994a6106186040e20fff871f53e5cb623193705fb4c93d8b9be01fc3aaaebf
docker rmi ubuntu
C:\Users2>docker rmi ubuntu
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:ac58ff7fe25edc58bdf0067ca99df00014dbd032e2246d30a722fa348fd799a5
Deleted: sha256:1f6ddc1b2547b2e38dc25b265ac585238a3c23da63976722864dab2a069c74f4
Deleted: sha256:966e94ab6e166fb358a208cfd8169d22dea352501c96700eb7f45092a2962ee6
๋‹ค์‹œ ์ „์ฒด ์ด๋ฏธ์ง€ ๋ณด๊ธฐ
C:\Users2>docker images
REPOSITORY          TAG                 IMAGE ID            CREATED
   SIZE

06) ubuntu 18.04 ๋‹ค์šด๋กœ๋“œ : docker pull

์‚ฌ์šฉ๋ฒ•) docker pull ์ด๋ฏธ์ง€๋ช…:ํƒœ๊ทธ
docker pull ubuntu:18.04
C:\Users2>docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
7c457f213c76: Pull complete
Digest: sha256:152dc042452c496007f07ca9127571cb9c29697f42acbfad72324b2bb2e43c98
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04
์ด๋ฏธ์ง€ ์ „์ฒด ๋ชฉ๋ก ๋ณด๊ธฐ
C:\Users2>docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              18.04               f9a80a55f492        8 days ago          63.2MB

C:\Users2>

07) ์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘ํ•˜๊ธฐ(๊ฐ€๋™)

์ปจํ…Œ์ด๋„ˆ ๊ฐ€๋™๊ณผ ๋™์‹œ์— ์ ‘์†ํ•˜๊ธฐ
์‚ฌ์šฉ๋ฒ•) docker run -it ์ด๋ฏธ์ง€๋ช…:ํƒœ๊ทธ bash
docker run -it ubuntu:18.04 bash
C:\Users2>docker run -it ubuntu:18.04 bash
root@7aea09695595:/#
–name ๋ณ„๋ช… : ์ปจํ…Œ์ด๋„ˆ ๋ณ„๋ช…์„ ์ง€์ •ํ•˜๋Š” ์˜ต์…˜

08) ์ปจํ…Œ์ด๋„ˆ์—์„œ ๋‚˜๊ฐ€๊ธฐ : exit

์ปจํ…Œ์ด๋„ˆ ์ค‘์ง€
root@7aea09695595:/# exit
exit
์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘ํ•˜๊ธฐ : docker start
์‚ฌ์šฉ๋ฒ•) docker start ์ปจํ…Œ์ด๋„ˆ๋ช…(์ปจํ…Œ์ด๋„ˆid, ๋ณ„๋ช…)
์ปจํ…Œ์ด๋„ˆ ์ „์ฒด ๋ชฉ๋ก ๋ณด๊ธฐ
docker ps -a
C:\Users2>docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
7aea09695595        ubuntu:18.04        "bash"              4 minutes ago       Exited (0) 2 minutes ago                       elegant_swartz

09) ์ปจํ…Œ์ด๋„ˆ ์‹œ์ž‘

docker start 7aea09695595
C:\Users2>docker start 7aea09695595
7aea09695595

10) ์ปจํ…Œ์ด๋„ˆ ๋‹ค์‹œ ์ ‘์†ํ•˜๊ธฐ : docker attach

์‚ฌ์šฉ๋ฒ•) docker attach ์ปจํ…Œ์ด๋„ˆ๋ช…(์ปจํ…Œ์ด๋„ˆid, ๋ณ„๋ช…)
docker attach 7aea09695595
C:\Users2>docker attach 7aea09695595
root@7aea09695595:/#

๐Ÿ“ƒ ์ปจํ…Œ์ด๋„ˆ ์กฐ์ž‘ ๋ฐ ์ด๋ฏธ์ง€ ์ž‘์„ฑ

1) ์ปจํ…Œ์ด๋„ˆ ์กฐ์ž‘ ๋ฐ ์ด๋ฏธ์ง€ ์ž‘์„ฑ

์šฐ๋ถ„ํˆฌ ๋ฆฌ๋ˆ…์Šค ์ตœ์‹  ํŒจํ‚ค์ง€ ๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ธฐ
์œˆ๋„์šฐ ์—…๋ฐ์ด๋“œ(๋ณด์•ˆ ๋ชจ๋“ˆ ๋ฐ›๊ธฐ, ๋ฒ„๊ทธํŒจ์น˜ ๋“ฑ) ์™€ ์œ ์‚ฌ
๋ฒ„๊ทธ(๋ฒŒ๋ ˆ) ํŒจ์น˜(์ˆ˜์ •) : it ์šฉ์–ด, ์˜ค๋™์ž‘ ๊ธฐ๋Šฅ์„ ์ˆ˜์ •ํ•œ ํŒจํ‚ค์ง€
apt-get : react ์˜ npm (ํŒจํ‚ค์ง€ ์„ค์น˜ ๋งค๋‹ˆ์ €) ๊ณผ ์œ ์‚ฌ
์‚ฌ์šฉ๋ฒ•) apt-get update
apt-get update
root@7aea09695595:/# apt-get update
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
...์ƒ๋žต

2) ์‚ฌ์šฉ๋ฒ•) apt-get install -y ํŒจํ‚ค์ง€๋ช…1 ํŒจ์ง€์ง€๋ช…2 …

-y ์˜ต์…˜ : ๋ชจ๋‘ yes ํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ
apt-get install -y iputils-ping net-tools iproute2 dnsutils curl : ๋„คํŠธ์› ํŒจํ‚ค์ง€ ์„ค์น˜
apt-get install -y iputils-ping
root@7aea09695595:/# apt-get install -y iputils-ping
Reading package lists... Done
Building dependency tree
...์ƒ๋žต
apt-get install -y net-tools
root@7aea09695595:/# apt-get install -y net-tools
Reading package lists... Done
Building dependency tree
...์ƒ๋žต
apt-get install -y iproute2
root@7aea09695595:/# apt-get install -y iproute2
Reading package lists... Done
Building dependency tree
Reading state information... Done
...์ƒ๋žต

3) ์ปดํ“จํ„ฐ์˜ IP ์ฃผ์†Œ ๋ณด๊ธฐ ๋ช…๋ น์–ด

IP ์ฃผ์†Œ : ๋„คํŠธ์›Œํฌ ์นด๋“œ ๋ถ€ํ’ˆ(ethernet card)
์‚ฌ์šฉ๋ฒ•) ifconfig ๋„คํŠธ์›ํฌ์นด๋“œ๋ช…(๊ธฐ๋ณธ:eth0)
ifconfig eth0
root@7aea09695595:/# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 5000  bytes 29507963 (29.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4147  bytes 230549 (230.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
์œ„์˜ ๋„คํŠธ์› ์ •๋ณด ํ•ด์„
inet ip์ฃผ์†Œ : ์ปดํ“จํ„ฐ ip ์ฃผ์†Œ(์‚ฌ์„ค ip)
broadcast ip์ฃผ์†Œ : ๋Œ€ํ‘œ ip ์ฃผ์†Œ(๊ณต์ธ ip)
inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255

4) ์—ฌ๋Ÿฌ ํ„ฐ๋ฏธ๋„์—์„œ ์กฐ์ž‘ํ•˜๊ธฐ

์ปจํ…Œ์ด๋„ˆ ์ ‘์†ํ•˜๊ธฐ : docker exec -it
์˜ˆ์ œ 1) ๋‹ค๋ฅธ ํ„ฐ๋ฏธ๋„์„ ์‹คํ–‰์‹œํ‚ค๊ณ  exec ๋ช…๋ น์–ด๋กœ ์ ‘์†ํ•˜๊ธฐ
์‚ฌ์šฉ๋ฒ•) docker exec -it ์ปจํ…Œ์ด๋„ˆ๋ช…(id, ๋ณ„๋ช…) bash
๋‹ค๋ฅธ ํ„ฐ๋ฏธ๋„ ์—ด๊ธฐ
์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ๋ชฉ๋ก ๋ณด๊ธฐ
docker ps
C:\Users2>docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
7aea09695595        ubuntu:18.04        "bash"              36 minutes ago      Up 31 minutes                           elegant_swartz
exec ๋ฅผ ์ด์šฉํ•ด์„œ ์ปจํ…Œ์ด๋„ˆ ์ ‘์†ํ•˜๊ธฐ
docker exec -it 7aea09695595 bash
C:\Users2>docker exec -it 7aea09695595 bash
root@7aea09695595:/#
์ฐธ๊ณ ) ๋ฆฌ๋ˆ…์Šค : ์—ฌ๋Ÿฌ ์‚ฌ๋žŒ์ด ๋™์‹œ ์ ‘์†ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” OS
์ปจํ…Œ์ด๋„ˆ : 1๋ช…์˜ ์œ ์ €๋ฅผ ์œ„ํ•œ ๊ฒƒ์ด ์ปจํ…Œ์ด๋„ˆ

๐Ÿ“ƒ ํ˜ธ์ŠคํŠธ์™€ ์ปจํ…Œ์ด๋„ˆ์˜ ๊ด€๊ณ„

ํ˜ธ์ŠคํŠธ : ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ์šด์˜์ฒด์ œ(๋ฆฌ๋ˆ…์Šค, ๋ฒ„์ธ„์–ผ๋ฐ•์Šค)
์ปจํ…Œ์ด๋„ˆ๋“ค : ๋ฆฌ๋ˆ…์Šค ์šด์˜์ฒด์ œ(OS) ๋ฅผ ๊ณต์œ ํ•ด์„œ ์‚ฌ์šฉํ•จ
๊ทธ๋ฆผ
์ปจํ…Œ์ด๋„ˆ 1 | ์ปจํ…Œ์ด๋„ˆ 2 | ์ปจํ…Œ์ด๋„ˆ 3 …
———————————————
๋ฆฌ๋ˆ…์Šค ์šด์˜์ฒด์ œ(OS, ๋ฒ„์ธ„์–ผ๋ฐ•์Šค์˜ ๋ฆฌ๋ˆ…์Šค)
———————————————
์ปจํ…Œ์ด๋„ˆ์˜ ํŠน์ง•
์ปจํ…Œ์ด๋„ˆ : ์‹คํ–‰์ค‘์ธ ํ”„๋กœ๊ทธ๋žจ, ์šด์˜์ฒด์ œ๋ฅผ ๊ณต์œ ํ•จ
์ปจํ…Œ์ด๋„ˆ์„ ์—ฌ๋Ÿฌ ๊ฐœ ๊ฐ€๋™ํ•˜๋ฉด ๋ถ„๋ฆฌ๋œ ์ปดํ“จํ„ฐ์ฒ˜๋Ÿผ ๋…๋ฆฝ์ ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ
์ปจํ…Œ์ด๋„ˆ๋Š” IP ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง€๋ฉด ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ๋“ค๊ณผ ํ†ต์‹ ์ด ๊ฐ€๋Šฅ
์ปจํ…Œ์ด๋„ˆ๋Š” 1๋ช…์˜ ์œ ์ €๋ฅผ ์œ„ํ•œ ๊ฒƒ
์ปจํ…Œ์ด๋„ˆ๋Š” ์™ธ๋ถ€์—์„œ(์œˆ๋„์šฐ์ฆˆ10) ์ปจํ…Œ์ด๋„ˆ์— ์ ‘์†ํ•  ์ˆ˜ ์—†์Œ
=> ์™ธ๋ถ€ ์ ‘์†์„ ์œ„ํ•ด์„œ๋Š” ํฌํŠธ ๊ฐœ๋ฐฉ์ด ํ•„์š”

๋‹ต๊ธ€ ๋‚จ๊ธฐ๊ธฐ

์ด๋ฉ”์ผ ์ฃผ์†Œ๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ํ•„๋“œ๋Š” *๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค