05. Docker ์ดํด๋ณด๊ธฐ
05. Docker ์ดํด๋ณด๊ธฐ ๊ด๋ จ
์ง๊ธ๊น์ง ๊ธฐ๋ณธ์ ์ธ ๋ช ๋ น ์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ด๋ฏธ์ง ์์ฑ ๋ฐฉ๋ฒ์ ์์๋ณด์์ต๋๋ค. ์ด ์ฅ์์๋ ์ด๋ฏธ์ง์ ์ปจํ ์ด๋์ ์ ๋ณด๋ฅผ ์กฐํํ๋ ๋ฐฉ๋ฒ, ์ปจํ ์ด๋์์ ํ์ผ์ ๊บผ๋ด๋ ๋ฐฉ๋ฒ, ๋ณ๊ฒฝ๋ ํ์ผ์ ํ์ธํ๋ ๋ฐฉ๋ฒ, ๋ณ๊ฒฝ ์ฌํญ์ ์ด๋ฏธ์ง๋ก ์ ์ฅํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
history
๋ช
๋ น์ผ๋ก ์ด๋ฏธ์ง ํ์คํ ๋ฆฌ ์ดํด๋ณด๊ธฐ
์์์ ์์ฑํ hello:0.1
์ด๋ฏธ์ง์ ํ์คํ ๋ฆฌ๋ฅผ ์กฐํํด๋ณด๊ฒ ์ต๋๋ค.
sudo docker history hello:0.1
#
# IMAGE CREATED CREATED BY SIZE COMMENT
# 8307ff628ec8 5 minutes ago /bin/sh -c #(nop) EXPOSE 443 0B
# adbb8a7ef64d 5 minutes ago /bin/sh -c #(nop) EXPOSE 80 0B
# a405f9d28415 5 minutes ago /bin/sh -c #(nop) CMD ["nginx"] 0B
# a9726f7e681e 5 minutes ago /bin/sh -c #(nop) WORKDIR /etc/nginx 0B
# 78f354dbdbcc 5 minutes ago /bin/sh -c #(nop) VOLUME [/data /etc/nginx/โฆ 0B
# 66f885084c19 5 minutes ago /bin/sh -c chown -R www-data:www-data /var/lโฆ 0B
# 5c54eb835f57 5 minutes ago /bin/sh -c echo "\ndaemon off;" >> /etc/nginโฆ 1.46kB
# 9fc2f61ad2f4 5 minutes ago /bin/sh -c apt install -y nginx 55.6MB
# 9c80ad1c1c34 6 minutes ago /bin/sh -c apt update 36.2MB
# 69b49943b930 6 minutes ago /bin/sh -c #(nop) MAINTAINER Foo Bar <foo@bโฆ 0B
# 2dc39ba059dc 7 days ago /bin/sh -c #(nop) CMD ["bash"] 0B
# <missing> 7 days ago /bin/sh -c #(nop) ADD file:a7268f82a86219801โฆ 77.8MB
docker history <์ด๋ฏธ์ง ์ด๋ฆ>:<ํ๊ทธ>
ํ์์
๋๋ค. ์ด๋ฏธ์ง ์ด๋ฆ ๋์ ์ด๋ฏธ์ง ID๋ฅผ ์ฌ์ฉํด๋ ๋ฉ๋๋ค.
์ด๋ ๊ฒ Dockefile์ ์ค์ ํ ๋๋ก ํ์คํ ๋ฆฌ๊ฐ ์์ฑ๋ฉ๋๋ค.
cp
๋ช
๋ น์ผ๋ก ํ์ผ ๊บผ๋ด๊ธฐ
hello-nginx
์ปจํ
์ด๋์์ ํ์ผ์ ๊บผ๋ด๋ณด๊ฒ ์ต๋๋ค.
sudo docker cp hello-nginx:/etc/nginx/nginx.conf ./
docker cp <์ปจํ
์ด๋ ์ด๋ฆ>:<๊ฒฝ๋ก> <ํธ์คํธ ๊ฒฝ๋ก>
ํ์์
๋๋ค.
ํ์ฌ ๋๋ ํฐ๋ฆฌ์ nginx.conf
ํ์ผ์ด ๋ณต์ฌ๋์์ต๋๋ค.
commit
๋ช
๋ น์ผ๋ก ์ปจํ
์ด๋์ ๋ณ๊ฒฝ์ฌํญ์ ์ด๋ฏธ์ง๋ก ์์ฑํ๊ธฐ
docker commit
๋ช
๋ น์ ์ปจํ
์ด๋์ ๋ณ๊ฒฝ ์ฌํญ์ ์ด๋ฏธ์ง ํ์ผ๋ก ์์ฑํฉ๋๋ค.
hello-nginx
์ปจํ
์ด๋ ์์ ํ์ผ ๋ด์ฉ์ด ๋ฐ๋์๋ค๊ณ ์น๊ณ , ์ปจํ
์ด๋๋ฅผ ์ด๋ฏธ์ง ํ์ผ๋ก ์์ฑํด๋ณด๊ฒ ์ต๋๋ค.
sudo docker commit -a "Foo Bar <foo@bar.com>" -m "add hello.txt" hello-nginx hello:0.2
docker commit <์ต์
> <์ปจํ
์ด๋ ์ด๋ฆ> <์ด๋ฏธ์ง ์ด๋ฆ>:<ํ๊ทธ>
ํ์์
๋๋ค. ์ปจํ
์ด๋ ์ด๋ฆ ๋์ ์ปจํ
์ด๋ ID๋ฅผ ์ฌ์ฉํด๋ ๋ฉ๋๋ค.
-a "Foo Bar <foo@bar.com>"๊ณผ -m "add hello.txt"
์ต์
์ผ๋ก ์ปค๋ฐํ ์ฌ์ฉ์์ ๋ก๊ทธ ๋ฉ์์ง๋ฅผ ์ค์ ํฉ๋๋ค. hello-nginx
์ปจํ
์ด๋๋ฅผ hello:0.2
์ด๋ฏธ์ง๋ก ์์ฑํฉ๋๋ค.
์ด๋ฏธ์ง ๋ชฉ๋ก์ ์ถ๋ ฅํฉ๋๋ค.
sudo docker images
#
# REPOSITORY TAG IMAGE ID CREATED SIZE
# hello 0.2 011ff3ff87e9 14 seconds ago 170MB
# hello 0.1 8307ff628ec8 6 minutes ago 170MB
# ubuntu 22.04 2dc39ba059dc 7 days ago 77.8MB
hello:0.2
์ด๋ฏธ์ง๊ฐ ์์ฑ๋์์ต๋๋ค.
diff
๋ช
๋ น์ผ๋ก ์ปจํ
์ด๋์์ ๋ณ๊ฒฝ๋ ํ์ผ ํ์ธํ๊ธฐ
docker diff
๋ช
๋ น์ ์ปจํ
์ด๋๊ฐ ์คํ๋๋ฉด์ ๋ณ๊ฒฝ๋ ํ์ผ ๋ชฉ๋ก์ ์ถ๋ ฅํฉ๋๋ค. ๋น๊ต ๊ธฐ์ค์ ์ปจํ
์ด๋๋ฅผ ์์ฑํ ์ด๋ฏธ์ง ๋ด์ฉ์
๋๋ค.
sudo docker diff hello-nginx
#
# C /etc
# C /etc/nginx
# A /etc/nginx/site-enabled
# A /data
# C /var
# C /var/lib
# C /var/lib/nginx
# A /var/lib/nginx/body
# A /var/lib/nginx/fastcgi
# A /var/lib/nginx/proxy
# A /var/lib/nginx/scgi
# A /var/lib/nginx/uwsgi
# C /run
# A /run/nginx.pid
docker diff <์ปจํ
์ด๋ ์ด๋ฆ>
ํ์์
๋๋ค. ์ปจํ
์ด๋ ์ด๋ฆ ๋์ ์ปจํ
์ด๋ ID๋ฅผ ์ฌ์ฉํด๋ ๋ฉ๋๋ค.
A
๋ ์ถ๊ฐ๋ ํ์ผ, C
๋ ๋ณ๊ฒฝ๋ ํ์ผ, D
๋ ์ญ์ ๋ ํ์ผ์
๋๋ค.
inspect
๋ช
๋ น์ผ๋ก ์ธ๋ถ ์ ๋ณด ํ์ธํ๊ธฐ
docker inspect
๋ช
๋ น์ ์ด๋ฏธ์ง์ ์ปจํ
์ด๋์ ์ธ๋ถ ์ ๋ณด๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
sudo docker inspect hello-nginx
#
# [
# {
# "Id": "9f4bb4c4a3d8698a31507febffba19a655caab5a0ee78452cc2c64ea406af7bd",
# "Created": "2022-09-09T03:11:49.391803068Z",
# "Path": "nginx",
# "Args": [],
# "State": {
# "Status": "running",
# ... ์๋ต ...
# },
# "Image": "sha256:8307ff628ec8900bc7a80eecc54bf6f21b6019ee96d22ca3e4152a06f704756d",
# ... ์๋ต ...
# "Name": "/hello-nginx",
# "RestartCount": 0,
# "Driver": "overlay2",
# "Platform": "linux",
# ... ์๋ต ...
# "HostConfig": {
# ... ์๋ต ...
# "NetworkMode": "default",
# "PortBindings": {
# "80/tcp": [
# {
# "HostIp": "",
# "HostPort": "80"
# }
# ]
# },
# ... ์๋ต ...
# },
# ... ์๋ต ...
# "Config": {
# "Hostname": "9f4bb4c4a3d8",
# "Domainname": "",
# "User": "",
# "AttachStdin": false,
# "AttachStdout": false,
# "AttachStderr": false,
# "ExposedPorts": {
# "443/tcp": {},
# "80/tcp": {}
# },
# "Tty": false,
# "OpenStdin": false,
# "StdinOnce": false,
# "Env": [
# "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# ],
# "Cmd": [
# "nginx"
# ],
# "Image": "hello:0.1",
# "Volumes": {
# "/data": {},
# "/etc/nginx/site-enabled": {},
# "/var/log/nginx": {}
# },
# "WorkingDir": "/etc/nginx",
# "Entrypoint": null,
# "OnBuild": null,
# "Labels": {}
# },
# "NetworkSettings": {
# "Bridge": "",
# "SandboxID": "0adee39c61d22d570a50a3e9ba174dc7901ffea732f6aca75e5ea00a330f9fa3",
# "HairpinMode": false,
# "LinkLocalIPv6Address": "",
# "LinkLocalIPv6PrefixLen": 0,
# "Ports": {
# "443/tcp": null,
# "80/tcp": [
# {
# "HostIp": "0.0.0.0",
# "HostPort": "80"
# },
# {
# "HostIp": "::",
# "HostPort": "80"
# }
# ]
# },
# ... ์๋ต ...
# }
# }
# ]
# }]
docker inspect <์ด๋ฏธ์ง ๋๋ ์ปจํ
์ด๋ ์ด๋ฆ>
ํ์์
๋๋ค. ์ด๋ฏธ์ง, ์ปจํ
์ด๋ ์ด๋ฆ ๋์ ์ด๋ฏธ์ง ID๋, ์ปจํ
์ด๋ ID๋ฅผ ์ฌ์ฉํด๋ ๋ฉ๋๋ค.