🌱 Infra/Container_Docker

[Docker-Basic (λ²ˆμ™Έ)] Docker Container Configure File

mini_world 2020. 9. 28. 14:14
λͺ©μ°¨ μ ‘κΈ°


 

이번 μ‹€μŠ΅μ—μ„œ λ‹€λ£° λ‚΄μš©μ€ 크게 μ€‘μš”ν•˜μ§€λŠ” μ•Šμ§€λ§Œ μ–Έμ  κ°€ ν•„μš”ν• μˆ˜λ„ μžˆκΈ°λ•Œλ¬Έμ— 별도 λ²ˆμ™Έλ‘œ μž‘μ„±ν•©λ‹ˆλ‹€ :)

도컀 ν”„λ‘œμ„ΈμŠ€λ₯Ό μ •μ˜ν•˜λŠ” νŒŒμΌμ— 직접 λ“€μ–΄κ°€μ„œ λ‚΄μš©μ„ μˆ˜μ •ν•˜λŠ” μ‹€μŠ΅μ„ μ§„ν–‰ν•©λ‹ˆλ‹€.

 

자, ν•œλ²ˆ ν•΄λ΄…μ‹œλ‹€! 😎

도컀 μ»¨ν…Œμ΄λ„ˆλ₯Ό μ‹€ν–‰ν•©λ‹ˆλ‹€.

[root@docker /]# docker container run --name nginx -d -p 8080:80 nginx
d66376e534babcd49e947d2766c01dac442a1c0daaa3d3f7643434b05bc210ae

λͺ©λ‘μ„ ν™•μΈν•΄λ΄…μ‹œλ‹€.

root@docker /]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
d66376e534ba        nginx               "/docker-entrypoint.…"   11 seconds ago      Up 11 seconds       0.0.0.0:8080->80/tcp   nginx

 

이제 도컀 데λͺ¬μ„ μž μ‹œ μ€‘μ§€ν•©λ‹ˆλ‹€.

[root@docker /]# systemctl stop docker 

/var/lib/docker/container κ²½λ‘œμ— λ“€μ–΄κ°€λ©΄ μ•„μ£Ό κΈ΄ λ¬Έμžκ°€ μžˆμ„ν…λ°, 이 λ¬ΈμžλŠ” Conteiner ID와 μ•žμͺ½μ΄ μΌμΉ˜ν•©λ‹ˆλ‹€ :)
μ—¬λŸ¬κ°œμ˜ μ»¨ν…Œμ΄λ„ˆκ°€ μžˆλŠ” 경우 μ»¨ν…Œμ΄λ„ˆ IDλ₯Ό ν™•μΈν•˜μ—¬ ꡬ뢄할 수 μžˆμŠ΅λ‹ˆλ‹€.
이 경둜둜 κ°€λ©΄ μ»¨ν…Œμ΄λ„ˆ 싀행에 ν•„μš”ν•œ νŒŒμΌλ“€μ„ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.
μ΄μ€‘μ—μ„œλ„ hostconfig.json νŒŒμΌμ„ 변경해보도둝 ν•˜κ² μŠ΅λ‹ˆλ‹€.

[root@docker /]# cd /var/lib/docker/containers/d66376e534babcd49e947d2766c01dac442a1c0daaa3d3f7643434b05bc210ae/
[root@docker d66376e534babcd49e947d2766c01dac442a1c0daaa3d3f7643434b05bc210ae]# ls -al
합계 28
drwx------. 4 root root  237  9μ›” 28 05:06 .
drwx------. 3 root root   78  9μ›” 28 05:06 ..
drwx------. 2 root root    6  9μ›” 28 05:06 checkpoints
-rw-------. 1 root root 2680  9μ›” 28 05:06 config.v2.json
-rw-r-----. 1 root root 1072  9μ›” 28 05:06 d66376e534babcd49e947d2766c01dac442a1c0daaa3d3f7643434b05bc210ae-json.log
-rw-r--r--. 1 root root 1512  9μ›” 28 05:06 hostconfig.json
-rw-r--r--. 1 root root   13  9μ›” 28 05:06 hostname
-rw-r--r--. 1 root root  174  9μ›” 28 05:06 hosts
drwx------. 2 root root    6  9μ›” 28 05:06 mounts
-rw-r--r--. 1 root root  102  9μ›” 28 05:06 resolv.conf
-rw-r--r--. 1 root root   71  9μ›” 28 05:06 resolv.conf.hash

hostconfig.json 파일 λ‚΄μš©μ€ μ•„λž˜μ™€ κ°™μŠ΅λ‹ˆλ‹€ :)
μ €λŠ” 이 λ‚΄μš©μ€‘μ— "HostPort":"8080" 값을 λ³€κ²½ν•΄μ€„κ²Œμš”. (vi에디터λ₯Ό μ‚¬μš©ν•˜μ—¬ λ³€κ²½ν•΄μ£Όμ„Έμš”)

[root@docker d66376e534babcd49e947d2766c01dac442a1c0daaa3d3f7643434b05bc210ae]# cat hostconfig.json 
{"Binds":null,"ContainerIDFile":"","LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"default","PortBindings":{"80/tcp":[{"HostIp":"","HostPort":"8080"}]},"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"]}

자 λ³€κ²½λœ ν›„μ˜ 값은 μ•„λž˜μ™€ κ°™μŠ΅λ‹ˆλ‹€. "HostPort":"8090"으둜 λ³€κ²½ν•˜μ˜€μŠ΅λ‹ˆλ‹€. 

[root@docker d66376e534babcd49e947d2766c01dac442a1c0daaa3d3f7643434b05bc210ae]# cat hostconfig.json | grep HostPort
{"Binds":null,"ContainerIDFile":"","LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"default","PortBindings":{"80/tcp":[{"HostIp":"","HostPort":"8090"}]},"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"]}

이제 Docker 데λͺ¬μ„ μ‹€ν–‰ν•˜κ³  μ»¨ν…Œμ΄λ„ˆ μƒνƒœλ₯Ό ν™•μΈν•©λ‹ˆλ‹€.
μ—­μ‹œλ‚˜ Stop된 μƒνƒœμž…λ‹ˆλ‹€.

[root@docker /]# systemctl start docker
[root@docker /]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
d66376e534ba        nginx               "/docker-entrypoint.…"   3 minutes ago       Exited (0) 2 minutes ago                       nginx

μ»¨ν…Œμ΄λ„ˆλ₯Ό μ‹€ν–‰ν•˜κ³  μƒνƒœλ₯Ό ν™•μΈν•©λ‹ˆλ‹€.
이제 μ •μƒμ μœΌλ‘œ UPμƒνƒœκ°€ λ˜μ—ˆλ„€μš”  "0.0.0.0:8090->80/tcp"으둜 λ³€κ²½λœκ²ƒ 확인이 κ°€λŠ₯ν•©λ‹ˆλ‹€ :)

[root@docker /]# docker start nginx
nginx
[root@docker /]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
d66376e534ba        nginx               "/docker-entrypoint.…"   3 minutes ago       Up 1 second         0.0.0.0:8090->80/tcp   nginx
728x90