반응형
1. 컨테이너 실행
[root@docker]# docker run -it nginx:latest bash
2. 컨테이너 Inspect
## 다른 터미널을 열어 현재 실행 중인 컨테이너 목록을 확인한다.
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
40ca2c420d22 nginx:latest "/docker-entrypoint.…" 14 seconds ago Up 13 seconds 80/tcp xenodochial_rubin
## 현재실행중인 nginx 컨테이너의 정보 출력
[root@OPENLDAP-TEST ~]# docker inspect xenodochial_rubin
[
{
"Id": "40ca2c420d22b29b26ee19e49b80068069fbadf370932ce765c26887fd81c6b0",
"Created": "2020-07-13T03:03:48.965713533Z",
"Path": "/docker-entrypoint.sh",
"Args": [
"bash"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 31366,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-07-13T03:03:49.289245508Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:8cf1bfb43ff5d9b05af9b6b63983440f137c6a08320fa7592197c1474ef30241",
"ResolvConfPath": "/var/lib/docker/containers/40ca2c420d22b29b26ee19e49b80068069fbadf370932ce765c26887fd81c6b0/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/40ca2c420d22b29b26ee19e49b80068069fbadf370932ce765c26887fd81c6b0/hostname",
"HostsPath": "/var/lib/docker/containers/40ca2c420d22b29b26ee19e49b80068069fbadf370932ce765c26887fd81c6b0/hosts",
"LogPath": "/var/lib/docker/containers/40ca2c420d22b29b26ee19e49b80068069fbadf370932ce765c26887fd81c6b0/40ca2c420d22b29b26ee19e49b80068069fbadf370932ce765c26887fd81c6b0-json.log",
"Name": "/xenodochial_rubin",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/cbdd976691f6e804996aed2db00c62e1305946c8b0996de5ab895f1a27bff3c4-init/diff:/var/lib/docker/overlay2/c1d18b42d213c10ee9fa649fc2efd4d0e843b919ddfb6a49c1cfa72c3ad520e0/diff:/var/lib/docker/overlay2/85ca5bd7fa8cf6f6a2a900e23186826c24080f6426e616940eec11a969a6c71c/diff:/var/lib/docker/overlay2/8b60a01d702a2f1103b0d7f07beee875265d16f864af4d8f7cf6344df2e865aa/diff:/var/lib/docker/overlay2/b510c14f732fa463350da3fa4cc78d7fdc86cac7024b700529cb18459197bbe3/diff:/var/lib/docker/overlay2/5b06bfad8b594fb3189e77fb3c9078ff734292d4ec0ca068f2ff41ba863a92d2/diff",
"MergedDir": "/var/lib/docker/overlay2/cbdd976691f6e804996aed2db00c62e1305946c8b0996de5ab895f1a27bff3c4/merged",
"UpperDir": "/var/lib/docker/overlay2/cbdd976691f6e804996aed2db00c62e1305946c8b0996de5ab895f1a27bff3c4/diff",
"WorkDir": "/var/lib/docker/overlay2/cbdd976691f6e804996aed2db00c62e1305946c8b0996de5ab895f1a27bff3c4/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "40ca2c420d22",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.19.1",
"NJS_VERSION=0.4.2",
"PKG_RELEASE=1~buster"
],
"Cmd": [
"bash"
],
"Image": "nginx:latest",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
},
"StopSignal": "SIGTERM"
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "2f9cb6cc538302f62e8403439a3143502d96cd1e2a6efcff7e45d92d3cbfd950",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": null
},
"SandboxKey": "/var/run/docker/netns/2f9cb6cc5383",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "1022c9f549ba244f8a65fe343896971f29e39c72d8951a8a429a10252c040e62",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "82b1922b40b3aebfb4f367a2c6ebfaf0ba9304ea6a00592c7b57d26e0f5f9d17",
"EndpointID": "1022c9f549ba244f8a65fe343896971f29e39c72d8951a8a429a10252c040e62",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
## 이중 아래와 같이
## "GraphDriver": {
## "Data": {
## "LowerDir": "/var/lib/docker/overlay2/cbdd976691f6e804996aed2db00c62e1305946c8b0996de5ab895f1a27bff3c4- ##init/diff:/var/lib/docker/overlay2/c1d18b42d213c10ee9fa649fc2efd4d0e843b919ddfb6a49c1cfa72c3ad520e0/diff:/var/lib/docker/overlay2/85ca5bd7fa8cf6f6a2a900e23186826c24080f6426e616940eec11a969a6c71c/diff:/var/lib/docker/overlay2/8b60a01d702a2f1103b0d7f07beee875265d16f864af4d8f7cf6344df2e865aa/diff:/var/lib/docker/overlay2/b510c14f732fa463350da3fa4cc78d7fdc86cac7024b700529cb18459197bbe3/diff:/var/lib/docker/overlay2/5b06bfad8b594fb3189e77fb3c9078ff734292d4ec0ca068f2ff41ba863a92d2/diff",
## "MergedDir": "/var/lib/docker/overlay2/cbdd976691f6e804996aed2db00c62e1305946c8b0996de5ab895f1a27bff3c4/merged",
## "UpperDir": "/var/lib/docker/overlay2/cbdd976691f6e804996aed2db00c62e1305946c8b0996de5ab895f1a27bff3c4/diff",
## "WorkDir": "/var/lib/docker/overlay2/cbdd976691f6e804996aed2db00c62e1305946c8b0996de5ab895f1a27bff3c4/work"
## },
## "Name": "overlay2"
## }
## LowerDir : 현재 nginx 이미지의 5개의 Layer
## UpperDir : 현재 컨테이너의 수정이 일어난 부분을 기록. 아래와 같이 확인 했을때 디렉토리내에 아무것도 없는 것을 확인
[root@docker diff]# pwd
/var/lib/docker/overlay2/cbdd976691f6e804996aed2db00c62e1305946c8b0996de5ab895f1a27bff3c4/diff
[root@docker diff]# ll
total 0
3. 컨테이너 내용 수정
## 컨테이너 안에서 plo 란 파일을 생성해보자
root@40ca2c420d22:/# cd /tmp
root@40ca2c420d22:/tmp# touch plo
root@40ca2c420d22:/tmp# ls -al
total 0
## 그리고 UpperDir을 다시 확인하면 아래와 같이 확인 할 수 있다.
[root@docker diff]# pwd
/var/lib/docker/overlay2/cbdd976691f6e804996aed2db00c62e1305946c8b0996de5ab895f1a27bff3c4/diff
[root@docker diff]# ll
total 0
drwxrwxrwt 2 root root 17 Jul 13 12:13 tmp
[root@docker diff]# cd tmp
[root@docker tmp]# ll
total 0
-rw-r--r-- 1 root root 0 Jul 13 12:13 plo
## diff로 달라진 내역 확인
## "C" : CHANGE , "A" : ADD, "D" : DELETE
[root@docker tmp]# docker diff 40ca2c420d22
C /tmp
A /tmp/plo
## 이상태에서 컨테이너를 종료 하고 다시 컨테이너를 실행하였을때 위에서 만든 plo란 파일은 반영 되지 않는다.
## 컨테이너가 종료되면 작업하던 디렉토리를 통채로 날려 버린다.
root@40ca2c420d22:/tmp# exit
exit
[root@docker diff]# docker run -it nginx:latest bash
root@57d7ca8ca5d0:/# cd /tmp
root@57d7ca8ca5d0:/tmp# ls -al
total 0
drwxrwxrwt 1 root root 6 Jul 22 2020 .
drwxr-xr-x 1 root root 6 Jul 13 03:32 ..
4. 컨테이너 수정 내용 반영
## docker commit <현재 컨테이너 ID> <새로운 이미지 이름:TAG> 으로 변경된 내용을 반영
[root@docker diff]# docker commit 40ca2c420d22 nginx:add_plo
sha256:1ce4194fd0ba2400726bb4cd92d3d6012764dc5cccf3be3d7bd73a2a808dbdd4
[root@docker diff]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 8cf1bfb43ff5 Less than a second ago 132MB
nginx add_plo 1ce4194fd0ba 20 seconds ago 132MB
## 실제 반영 확인
[root@docker diff]# docker run -it nginx:add_plo bash
root@da3e928eea4b:/# cd /tmp
root@da3e928eea4b:/tmp# ls -al
total 0
drwxrwxrwt 1 root root 17 Jul 13 03:13 .
drwxr-xr-x 1 root root 6 Jul 13 03:33 ..
-rw-r--r-- 1 root root 0 Jul 13 03:13 plo
## Layer 히스토리를 비교해보면 다음과 같이 확인 할 수 있다.
[root@docker diff]# docker history nginx:add_plo
IMAGE CREATED CREATED BY SIZE COMMENT
1ce4194fd0ba 4 minutes ago bash 0B
8cf1bfb43ff5 Less than a second ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
<missing> Less than a second ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B
<missing> Less than a second ago /bin/sh -c #(nop) EXPOSE 80 0B
<missing> Less than a second ago /bin/sh -c #(nop) ENTRYPOINT ["/docker-entr… 0B
<missing> Less than a second ago /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7… 1.04kB
<missing> Less than a second ago /bin/sh -c #(nop) COPY file:1d0a4127e78a26c1… 1.96kB
<missing> Less than a second ago /bin/sh -c #(nop) COPY file:e7e183879c35719c… 1.2kB
<missing> Less than a second ago /bin/sh -c set -x && addgroup --system -… 63.3MB
<missing> Less than a second ago /bin/sh -c #(nop) ENV PKG_RELEASE=1~buster 0B
<missing> Less than a second ago /bin/sh -c #(nop) ENV NJS_VERSION=0.4.2 0B
<missing> Less than a second ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.19.1 0B
<missing> Less than a second ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B
<missing> Less than a second ago /bin/sh -c #(nop) CMD ["bash"] 0B
<missing> Less than a second ago /bin/sh -c #(nop) ADD file:6ccb3bbcc69b0d44c… 69.2MB
[root@docker diff]# docker history nginx:latest
IMAGE CREATED CREATED BY SIZE COMMENT
8cf1bfb43ff5 Less than a second ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B
<missing> Less than a second ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B
<missing> Less than a second ago /bin/sh -c #(nop) EXPOSE 80 0B
<missing> Less than a second ago /bin/sh -c #(nop) ENTRYPOINT ["/docker-entr… 0B
<missing> Less than a second ago /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7… 1.04kB
<missing> Less than a second ago /bin/sh -c #(nop) COPY file:1d0a4127e78a26c1… 1.96kB
<missing> Less than a second ago /bin/sh -c #(nop) COPY file:e7e183879c35719c… 1.2kB
<missing> Less than a second ago /bin/sh -c set -x && addgroup --system -… 63.3MB
<missing> Less than a second ago /bin/sh -c #(nop) ENV PKG_RELEASE=1~buster 0B
<missing> Less than a second ago /bin/sh -c #(nop) ENV NJS_VERSION=0.4.2 0B
<missing> Less than a second ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.19.1 0B
<missing> Less than a second ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B
<missing> Less than a second ago /bin/sh -c #(nop) CMD ["bash"] 0B
<missing> Less than a second ago /bin/sh -c #(nop) ADD file:6ccb3bbcc69b0d44c… 69.2MB
## Layer 확인
[root@docker diff]# docker image inspect nginx:add_plo | jq .[].RootFS
{
"Type": "layers",
"Layers": [
"sha256:95ef25a3204339de1edf47feaa00f60b5ac157a498964790c58c921494ce7ffd",
"sha256:d899691659b0a023be369ea77d6dedcf959aa50fcfdfd97603983b5f94296c20",
"sha256:227442bb48dc0fb87876f4e4b767718f45c88f888f15ad22cca38193f99559f7",
"sha256:1698c1b7e3e687db0079af289f1685cd2526c21d80d5b13b3ba0e9b191b9fb6f",
"sha256:98b4c818e603e05abe4963d66b975deaeab44997972f7f69533af9be1293de78",
"sha256:9bc46fc8eb2c8d1673c18372dc7b75c9f5aa10c2113c602f124b3af18377487d"
]
}
반응형
'Micro Service Architecture > Docker' 카테고리의 다른 글
5. [docker] container run (0) | 2021.03.16 |
---|---|
4. [docker] container, image 삭제 (0) | 2021.03.16 |
3. [docker] dockerfile build (0) | 2021.03.16 |
1. [docker] images (0) | 2021.03.16 |
0. [docker] 설치 (0) | 2021.03.16 |