์ด๋ฒ ์ค์ต์์ Docker ์ปจํ ์ด๋์ ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ์ ์ค์ตํฉ๋๋ค. ๐
Docker ์ปจํ
์ด๋์ Status์ ๋ผ์ดํ์ฌ์ดํด(=๋ช
๋ น์ด)์ ์๋ ์ฐธ๊ณ ์ฌ์ง์์ ํ์ธํ ์์์ต๋๋ค.
* Docker ์ปจํ
์ด๋์ 5๊ฐ์ง Status : created, running, stopped, paused, deleted
์ด์ ๊ฐ ๋ช ๋ น์ด๋ฅผ ํ๋์ฉ ์คํ ํด๋ณด๋ฉด์ ์ค์ตํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค :)
1. ์ปจํ ์ด๋ ์์ฑ ๋ฐ ํ์ธ
1-1) Create ( pull + create )
Create ๋ช
๋ น์ด๋ ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์ค๊ณ , ์ปจํ
์ด๋๋ฅผ ์์ฑํ๋ ๋ช
๋ น์ด ์
๋๋ค.
Create ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ์ปจํ
์ด๋๋ ์์ฑ๋์ง๋ง, Start๋ฅผ ๋ณ๋๋ก ํด์ฃผ์ด์ผ ์ปจํ
์ด๋๊ฐ ์คํ๋ฉ๋๋ค.
# Docker container create ๋ช
๋ น์ด๋ฅผ ํตํด httpd ์ปจํ
์ด๋๋ฅผ ์์ฑํด๋ด
์๋ค :)
[root@docker /]# docker container create --name webserver -p 80:80 httpd
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
d121f8d1c412: Pull complete
9cd35c2006cf: Pull complete
b6b9dec6e0f8: Pull complete
fc3f9b55fcc2: Pull complete
802357647f64: Pull complete
Digest: sha256:5ce7c20e45b407607f30b8f8ba435671c2ff80440d12645527be670eb8ce1961
Status: Downloaded newer image for httpd:latest
64c1174446d8c95377f214c90d242442a29fa821708be29e42c49b0ad50828d7
์ด๋ฏธ์ง๋ฅผ ํ์ธํด๋ณด๊ฒ ์ต๋๋ค.
[root@docker /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
httpd latest 417af7dc28bc 12 days ago 138MB
#docker container ls -a ๋ช
๋ น์ด๋ฅผ ํตํด ์ปจํ
์ด๋์ ํ์ฌ ์ํ๋ฅผ ํ์ธํ๊ฒ ์ต๋๋ค.
STATUS๋ฅผ ํ์ธํด๋ณด๋ฉด Running ์ํ๊ฐ ์๋ Created ์ํ๋ก ๋์ด์๋๊ฒ์ ๋ณผ์ ์์ต๋๋ค.
์ฆ, ์ปจํ
์ด๋๋ฅผ ์์ฑํ์ง๋ง ์คํ์ค์ ์๋๋๋ค.
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64c1174446d8 httpd "httpd-foreground" 19 seconds ago Created webserver
์ปจํ
์ด๋๋ฅผ ์ด์ ์์ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
[root@docker /]# docker container start webserver
webserver
์ปจํ ์ด๋ ์ํ๋ฅผ ํ์ธํฉ๋๋ค. ์ด์ Status(์ํ)๊ฐ UP์ ๋๋ค. :)
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64c1174446d8 httpd "httpd-foreground" About a minute ago Up 4 seconds 0.0.0.0:80->80/tcp webserver
1-2) run ( pull + create + start )
Run ๋ช
๋ น์ด๋ ์ด๋ฏธ์ง๋ฅผ pullํ๊ณ ์ปจํ
์ด๋ ์ด๋ฏธ์ง๋ฅผ createํ๊ณ , startํฉ๋๋ค :)
์์ Create๋ช
๋ น์ด์ ๋ฌ๋ฆฌ RUN ๋ช
๋ น์ด๋ ๋ณ๋๋ก ์ปจํ
์ด๋๋ฅผ ์คํ์ํค์ง ์์๋ ์ปจํ
์ด๋๊ฐ ์คํ๋ฉ๋๋ค.
์, ๋จผ์ run ๋ช ๋ น์ด๋ก nginx๋ฅผ ์์ํด๋ด ์๋ค.
[root@docker /]# docker container run --name nginx -d -p 8080:80 nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
d121f8d1c412: Already exists
ebd81fc8c071: Pull complete
655316c160af: Pull complete
d15953c0e0f8: Pull complete
2ee525c5c3cc: Pull complete
Digest: sha256:c628b67d21744fce822d22fdcc0389f6bd763daac23a6b77147d0712ea7102d0
Status: Downloaded newer image for nginx:latest
45580502d3b874b1c844d0c9b48bcf10b4ab93f989d70d28b573f70826229fa9
๋์ปค ์ปจํ
์ด๋ ๋ชฉ๋ก์ ํ์ธํฉ๋๋ค.
์ด๋ฒ์๋ ๋ณ๋๋ก Start ํ์ง ์์์ง๋ง ์ปจํ
์ด๋๊ฐ ์คํ๋๊ณ ์์ต๋๋ค.
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 6 seconds ago Up 5 seconds 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 5 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp webserver
2. ์ปจํ ์ดํฐ ์ค์ง ๋ฐ ์ฌ์คํ
์ด๋ฒ์๋ ์ปจํ ์ด๋๋ฅผ ์ค์งํ๊ณ ๋ค์ ์์ํ๋ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํด๋ณด๊ฒ ์ต๋๋ค.
์, ์ง๊ธ ๋๊ฐ์ ์ปจํ ์ด๋๊ฐ ์คํ๋๊ณ ์์ต๋๋ค :)
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 6 seconds ago Up 5 seconds 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 5 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp webserver
์ด์ nginx ์ปจํ ์ด๋๋ฅผ ์ค์งํ๊ฒ ์ต๋๋ค.
[root@docker /]# docker container stop nginx
nginx
์ปจํ
์ด๋ ์ํ๋ฅผ ๋ค์ํ๋ฒ ํ์ธํ๊ฒ ์ต๋๋ค.
nginx ์ปจํ
์ด๋ STATUS๊ฐ Exited ์ํ์
๋๋ค.
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" About a minute ago Exited (0) 2 seconds ago nginx
64c1174446d8 httpd "httpd-foreground" 7 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp webserver
์ด์ nginx ์ปจํ ์ด๋๋ฅผ ๋ค์ ์์ ํ๊ฒ ์ต๋๋ค.
[root@docker /]# docker container restart nginx
nginx
์ปจํ
์ด๋ ์ํ๋ฅผ ๋ค์ํ๋ฒ ํ์ธํฉ๋๋ค.
์ด์ nginx ์ปจํ
์ด๋์ Status๊ฐ UP์ํ๊ฐ ๋์์ต๋๋ค.
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 2 minutes ago Up 1 second 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 7 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp webserver
3. ์ปจํ ์ด๋ ์ผ์์ค์ง
์ด๋ฒ์๋ nginx ์ปจํ
์ด๋๋ฅผ ์ผ์์ค์ง(pause)ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
[root@docker /]# docker container pause nginx
nginx
nginx ์ปจํ ์ด๋์ Status๊ฐ UP (Paused)์ธ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 5 minutes ago Up 3 minutes (Paused) 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 10 minutes ago Up 9 minutes 0.0.0.0:80->80/tcp webserver
์ด๋ฒ์๋ ์ผ์์ค์ง๋ฅผ ํ๊ฒ ์ต๋๋ค.
[root@docker /]# docker container unpause nginx
nginx
nginx ์ปจํ ์ด๋์ Status๊ฐ UP์ธ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 5 minutes ago Up 3 minutes 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 11 minutes ago Up 9 minutes 0.0.0.0:80->80/tcp webserver
4. ์ปจํ ์ด๋ ๋ด๋ถ ์ ๋ณด ํ์ธํ๊ธฐ
์ปจํ ์ด๋์ ๋ด๋ถ์ ๋ณด๋ฅผ ํ์ธํ ์ ์๋ ๋ช ๋ น์ด๋ฅผ ํ์ธํฉ๋๋ค.
[root@docker /]# docker container inspect nginx
[
{
"Id": "45580502d3b874b1c844d0c9b48bcf10b4ab93f989d70d28b573f70826229fa9",
"Created": "2020-09-28T04:15:34.48069232Z",
"Path": "/docker-entrypoint.sh",
"Args": [
"nginx",
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 4048,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-09-28T04:17:38.822151268Z",
"FinishedAt": "2020-09-28T04:17:15.43676131Z"
},
-- ์๋ต --
]
5. ์ปจํ ์ด๋ ์ ์ ๋ฐ ํ์ผ ๋ณ๊ฒฝํ๊ธฐ (index.html)
์ปจํ
์ด๋์ ๋ชฉ๋ก์ ํ์ธํ๊ฒ ์ต๋๋ค.
์ด๋ฒ์๋ nginx ์ปจํ
์ด๋์ ์ ์ํด์ index.html ํ์ผ์ ๋ด์ฉ์ ์์ ํด๋ณด๊ฒ ์ต๋๋ค.
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 9 minutes ago Up 7 minutes 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 15 minutes ago Up 13 minutes 0.0.0.0:80->80/tcp webserver
nginx ์ปจํ ์ด๋์ ์ ์ํฉ๋๋ค.
[root@docker /]# docker container exec -it nginx /bin/bash
์ปจํ
์ด๋์ ์ ์ ๋์์ต๋๋ค.
์ด์ index.html ํ์ผ์ ์๋ก์ด ๋ด์ฉ์ ์
๋ ฅํ๊ณ ์ปจํ
์ด๋์์ ๋์ต๋๋ค.
root@45580502d3b8:/# echo 'Docker Container - test' > /usr/share/nginx/html/index.html
root@45580502d3b8:/# exit
exit
nginx http ์ถ๋ ฅ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํด๋ด ์๋ค :)
[root@docker /]# curl 127.0.0.1:8080/index.html
Docker Container - test
6. ์ปจํ ์ด๋ ๋ก๊ทธ ์ ๋ณด ํ์ธ
์ปจํ
์ด๋ ์คํ์ ์ค๋ฅ๊ฐ ๋์ ๋ก๊ทธ๋ฅผ ํ์ธํด๋ด์ผํ ๋, ์ด๋ป๊ฒ ๋ณผ์์์๊น์ ?
์ปจํ
์ด๋ ๋ด๋ถ์ ๋ก๊ทธ๋ฅผ ํ์ธํฉ๋๋ค.
์ปจํ
์ด๋์ ๋ชฉ๋ก์ ํ์ธํด๋ด
์๋ค.
๋๊ฐ์ ์ปจํ
์ด๋๊ฐ ์ด์์ค์ด๋, ๋๊ฐ ๋ชจ๋ ๋ก๊ทธ๋ฅผ ํ์ธํด๋ด
์๋ค!
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 9 minutes ago Up 7 minutes 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 15 minutes ago Up 13 minutes 0.0.0.0:80->80/tcp webserver
๋จผ์ nginx ์ปจํ
์ด๋์ ๋ก๊ทธ๋ฅผ ํ์ธํด๋ด
์๋ค.
์์์ index.html ํ์ด์ง ์์ฒญํ๊ฒ๋ ๋ก๊ทธ๋ก ๋จ์์๋ค์ :)
[root@docker /]# docker container logs -f nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: error: IPv6 listen already enabled
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
172.17.0.1 - - [28/Sep/2020:04:26:56 +0000] "GET /index.html HTTP/1.1" 200 24 "-" "curl/7.29.0" "-"
์ด๋ฒ์๋ webserver(httpd)๋ก๊ทธ๋ฅผ ํ์ธํด๋ด ๋๋ค.
[root@docker /]# docker container logs -f webserver
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Mon Sep 28 04:11:59.349361 2020] [mpm_event:notice] [pid 1:tid 139753489142912] AH00489: Apache/2.4.46 (Unix) configured -- resuming normal operations
[Mon Sep 28 04:11:59.349535 2020] [core:notice] [pid 1:tid 139753489142912] AH00094: Command line: 'httpd -D FOREGROUND'
209.17.96.42 - - [28/Sep/2020:04:33:31 +0000] "GET / HTTP/1.1" 200 45
7. ์ปจํ ์ด๋ ์ํ ์ ๋ณด ํ์ธ
๊ทธ๋ผ ์ปจํ
์ด๋์ CPU Memory ์ฌ์ฉ๋ ๋ฑ์ ์ค์๊ฐ ์ ๋ณด๋ ์ด๋ป๊ฒ ํ์ธํ ๊น์?
stats ๋ช
๋ น์ด๋ก ์ํ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค, ํ์ธ ํด๋ด
์๋ค :)
[root@docker /]# docker container stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
45580502d3b8 nginx 0.00% 1.406MiB / 7.392GiB 0.02% 1.39kB / 682B 0B / 0B 2
64c1174446d8 webserver 0.00% 17.09MiB / 7.392GiB 0.23% 2.82kB / 1.53kB 0B / 0B 109
8. ์ปจํ ์ด๋ ํ๋ก์ธ์ค ๋ฐ ํฌํธ ํ์ธ
์ปจํ ์ด๋ ๋ชฉ๋ก์ ํ์ธํฉ๋๋ค.
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 28 minutes ago Up 26 minutes 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 33 minutes ago Up 31 minutes 0.0.0.0:80->80/tcp webserver
nginx ์ปจํ
์ด๋ ๋ด๋ถ์ ์ด๋ค ํ๋ก์ธ์ค๊ฐ ๊ตฌ๋์ค์ธ์ง ํ์ธํ ์ ์์ต๋๋ค.
nginx ํ๋ก์ธ์ค๋ค์ :)
<!-- ์ปจํ
์ด๋ nginx์ ํ๋ก์ธ์ค ํ์ธ -->
[root@docker /]# docker container top nginx
UID PID PPID C STIME TTY TIME CMD
root 4048 4031 0 04:17 ? 00:00:00 nginx: master process nginx -g daemon off;
101 4092 4048 0 04:17 ? 00:00:00 nginx: worker process
nginx ์ปจํ
์ด๋์์ ์ฌ์ฉํ๋ ํฌํธ๋ฅผ ํ์ธํด๋ด
์๋ค.
์ปจํ
์ด๋ 80ํฌํธ๊ฐ ํธ์คํธ ์ปดํจํฐ์ 8080ํฌํธ๋ก ์ฐ๊ฒฐ๋์ด์๋ค์ :)
[root@docker /]# docker container port nginx
80/tcp -> 0.0.0.0:8080
์ด๋ฒ์๋ webserver ์ปจํ
์ด๋๋ฅผ ํ์ธํด๋ด
์๋ค!
์ง๊ธ webserver ์ปจํ
์ด๋์์ ์ด์๋๊ณ ์๋ ํ๋ก์ธ์ค์
๋๋ค.
[root@docker /]# docker container top webserver
UID PID PPID C STIME TTY TIME CMD
root 3662 3644 0 04:11 ? 00:00:00 httpd -DFOREGROUND
bin 3689 3662 0 04:11 ? 00:00:00 httpd -DFOREGROUND
bin 3690 3662 0 04:11 ? 00:00:00 httpd -DFOREGROUND
bin 3691 3662 0 04:11 ? 00:00:00 httpd -DFOREGROUND
bin 4244 3662 0 04:41 ? 00:00:00 httpd -DFOREGROUND
webserver ์ปจํ ์ด๋์์ ์ฌ์ฉํ๋ ํฌํธ๋ 80ํฌํธ์ด๋ฉฐ, ํธ์คํธ ์ปดํจํฐ์๋ 80 ํฌํธ์ ๋งคํ๋์ด์๋ค์ :)
[root@docker /]# docker container port webserver
80/tcp -> 0.0.0.0:80
9. ์ปจํ ์ด๋ ์ด๋ฆ ๋ณ๊ฒฝํ๊ธฐ
์ปจํ ์ด๋์ ๋ชฉ๋ก์ ํ์ธํด๋ด ๋๋ค. webserver ์ปจํ ์ด๋์ ์ด๋ฆ์ ๋ฐ๊ฟ๋ณผ๊น์?
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 31 minutes ago Up 29 minutes 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 36 minutes ago Up 34 minutes 0.0.0.0:80->80/tcp webserver
docker container rename <์ปจํ ์ด๋ ์ง๊ธ์ฐ๋์ด๋ฆ> <์ปจํ ์ด๋ ๋ฐ๊ฟ ์ด๋ฆ> ๋ช ๋ น์ด๋ฅผ ํตํด ์ด๋ฆ์ ๋ณ๊ฒฝํฉ๋๋ค.
[root@docker /]# docker container rename webserver apache_server
์ ๋ณ๊ฒฝ ๋์๋์ง ํ์ธํด๋ด
๋๋ค :)
apache_server๋ก ์ ๋ณ๊ฒฝ๋์๋ค์.
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 31 minutes ago Up 29 minutes 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 36 minutes ago Up 35 minutes 0.0.0.0:80->80/tcp apache_server
10. ์ปจํ ์ด๋์ ํ์ผ ๋ณต์ฌํ๊ธฐ
์ด๋ฒ์๋ ํธ์คํธ ์ปดํจํฐ์ index2.html ํ์ผ์ ์ปจํ ์ด๋๋ก ๋ณต์ฌ ๋ถ์ฌ๋ฃ๊ธฐ ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. :)
์ปจํ
์ด๋ ๋ชฉ๋ก์ ํ์ธํด๋ด
์๋ค.
์ด๋ฒ์๋ apache_server ์ปจํ
์ด๋๋ฅผ ์ฌ์ฉํด๋ด
์๋ค!
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 34 minutes ago Up 32 minutes 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 39 minutes ago Up 38 minutes 0.0.0.0:80->80/tcp apache_server
์, ๋จผ์ apache_server ์ปจํ ์ด๋์ ์น์๋ฒ๊ฐ ์ ๋์ํ๊ณ ์๋์ง ํ์ธํด๋ด ์๋ค.
[root@docker /]# curl 127.0.0.1:80/index.html
<html><body><h1>It works!</h1></body></html>
์ด์ index2.html ํ์ผ์ ์์ฑํ๊ฒ ์ต๋๋ค.
[root@docker /]# echo 'This is Docker test - File COPY' > index2.html
์ด์ ์ด ํ์ผ์ ์ปจํ
์ด๋์ ๋ณต์ฌํ๊ฒ ์ต๋๋ค.
๋ช
๋ น์ด๋ docker container cp <์๋ณธํ์ผ> <์ปจํ
์ด๋๋ช
>:<๊ฒฝ๋ก> ์
๋๋ค :)
[root@docker /]# docker container cp index2.html apache_server:/usr/local/apache2/htdocs/
์ ์ด์ ์ ๋ณต์ฌ๋์๋ ํ์ธํด๋ณผ๊น์!
index2.html ํ์ผ์ด ์ปจํ
์ด๋ ๋ด๋ถ๋ก ๋ณต์ฌ ๋์๊ณ , index2.html ์์ฒญ์ ์๋ต ์ ํ๋ค์!!
[root@docker /]# curl 127.0.0.1:80/index2.html
This is Docker test - File COPY
11. ์ปจํ ์ด๋ ๋ณ๊ฒฝ ์ ๋ณด ํ์ธํ๊ธฐ
์ ๋จ๊ณ์์ index2.html์ด๋ผ๋ ํ์ผ์ ์ปจํ
์ด๋ ๋ด๋ถ์ ๋ณต์ฌํด๋ฃ์์ต๋๋ค.
diff ๋ช
๋ น์ด๋ก ๋์ปค ์ปจํ
์ด๋ ๋ณ๊ฒฝ์ ๋ณด ํ์ธ ํด๋ณด๊ฒ ์ต๋๋ค. index2.html์ ์๋ก ์ถ๊ฐ๋์ด A ํ๊ทธ๊ฐ ๋ถ์ด์๋ค์!
* 'C'๋ Change, 'A'๋ Add, 'D'๋ Delete
[root@docker /]# docker container diff apache_server
C /usr
C /usr/local
C /usr/local/apache2
C /usr/local/apache2/logs
A /usr/local/apache2/logs/httpd.pid
C /usr/local/apache2/htdocs
A /usr/local/apache2/htdocs/index2.html
12. ์ปจํ ์ด๋ ์ญ์ ํ๊ธฐ
์ด์ ๋ง์ง๋ง ๋จ๊ณ์
๋๋ค.
์ปจํ
์ด๋๋ฅผ ์์ฑํ๊ณ ์ด์ํด๋ณด์์ผ๋, ์ด์ ์ญ์ ํด๋ณผ๊น์!
์ปจํ
์ด๋์ ๋ชฉ๋ก์ ํ์ธํด๋ด
์๋ค!
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 39 minutes ago Up 37 minutes 0.0.0.0:8080->80/tcp nginx
64c1174446d8 httpd "httpd-foreground" 45 minutes ago Up 43 minutes 0.0.0.0:80->80/tcp apache_server
์ปจํ
์ด๋ remove(rm) ๋ช
๋ น์ด๋ฅผ ์ด์ฉํด์ ์ปจํ
์ด๋๋ฅผ ์ญ์ ํด๋ณผ๊น์?
์, ์๋ฌ๊ฐ ๋์ค๋ค์.
๊ทธ ์ด์ ๋ ์คํ์ค์ธ ์ปจํ
์ด๋๋ stop ์ดํ์ remove ํ ์์๊ธฐ ๋๋ฌธ์
๋๋ค.
[root@docker /]# docker rm apache_server
Error response from daemon: You cannot remove a running container 64c1174446d8c95377f214c90d242442a29fa821708be29e42c49b0ad50828d7. Stop the container before attempting removal or force remove
์ด๋ฒ์๋ f ์ต์
์ ์ค์ ๊ฐ์ ๋ก ์ญ์ ํด๋ณด๊ฒ ์ต๋๋ค.
[root@docker /]# docker rm apache_server -f
apache_server
์ ์ง์์ก๋์ง ๋ชฉ๋ก์ ํ์ธํด๋ด
๋๋ค.
์ญ์ ๊ฐ ์ ๋์์ต๋๋ค :)
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 40 minutes ago Up 38 minutes 0.0.0.0:8080->80/tcp nginx
Prune ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํด๋ณผ๊ฑด๋ฐ, ์ด ๋ช ๋ น์ด๋ ์ค์ง์ํ์ธ ์ปจํ ์ด๋๋ฅผ ์ ์ฒด ์ญ์ ํ๋ ๋ช ๋ น์ด ์ ๋๋ค.
[root@docker /]# docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
์ง๊ธ์ ์ค์ง์ํ์ธ ์ปจํ ์ด๋๊ฐ ์์ด์, ์ํ ๊ทธ๋๋ก ์ ์ง๋ฉ๋๋ค. ๊ฒฐ๊ณผ ํ์ธํด๋ณผ๊ฒ์ :)
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45580502d3b8 nginx "/docker-entrypoint.…" 42 minutes ago Up 39 minutes 0.0.0.0:8080->80/tcp nginx
๊ทธ๋ฐ๋ฐ ์ด๋ ๊ฒ ํ๋ํ๋ ์ญ์ ํ๋๊ฒ ๊ท์ฐฎ์๋ ํ๋ฒ์ ๋ ๋ฆด์ ์๋ ๋ช
๋ น์ด๊ฐ ์์๊น์?
์ ์ฒด ์ญ์ ํด๋ด
์๋ค!
[root@docker /]# docker container rm -f $(docker ps -aq)
45580502d3b8
์ปจํ
์ด๋ ๋ชฉ๋ก์ ํ์ธํด๋ด
์๋ค :)
์ ๋ถ ๋ค ์ ์ญ์ ๋์๋ค์.
[root@docker /]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
์๊ณ ํ์ จ์ต๋๋ค. ๐ฅณ