docker container 설정 수정하기
docker run 이후 policy의 수정을 위해서는 다음 2가지 방법이 있음
- docker update
docker update --restart=always <container>
- /var/lib/docker/containers/CONTAINER_ID/hostconfig.json 파일 edit
{"Binds":["/nexus-data:/nexus-data"],"ContainerIDFile":"","LogConfig":{"Type":"journald","Config":{}},"NetworkMode":"default","PortBindings":{"8081/tcp":[{"HostIp":"","HostPort":"8081"}]},"RestartPolicy":{"Name":"always","MaximumRetryCount":0},"AutoRemove":false,"VolumeDriver":"","VolumesFrom":null,"CapAdd":null,"CapDrop":null,"Dns":[],"DnsOptions":[],"DnsSearch":[],"ExtraHosts":null,"GroupAdd":null,"IpcMode":"","Cgroup":"","Links":[],"OomScoreAdj":0,"PidMode":"","Privileged":true,"PublishAllPorts":false,"ReadonlyRootfs":false,"SecurityOpt":["label=disable"],"UTSMode":"","UsernsMode":"","ShmSize":67108864,"Runtime":"docker-runc","ConsoleSize":[0,0],"Isolation":"","CpuShares":0,"Memory":0,"NanoCpus":0,"CgroupParent":"","BlkioWeight":0,"BlkioWeightDevice":null,"BlkioDeviceReadBps":null,"BlkioDeviceWriteBps":null,"BlkioDeviceReadIOps":null,"BlkioDeviceWriteIOps":null,"CpuPeriod":0,"CpuQuota":0,"CpuRealtimePeriod":0,"CpuRealtimeRuntime":0,"CpusetCpus":"","CpusetMems":"","Devices":[],"DiskQuota":0,"KernelMemory":0,"MemoryReservation":0,"MemorySwap":0,"MemorySwappiness":-1,"OomKillDisable":false,"PidsLimit":0,"Ulimits":null,"CpuCount":0,"CpuPercent":0,"IOMaximumIOps":0,"IOMaximumBandwidth":0}
docker log 보기
- docker logs -f <> : 실행중인 로그 확인 할 경우
- docker events& : event 발생 로그 확인 (터미널을 2개 여는게 좋음)
- docker start -a <> : 실행시 일어나는 오류 확인 가능
docker inspect
container의 상세 정보를 확인하는 명령어 이다.
docker inspect <<containerid>>
해당 명령어를 실행 하면 아래와 같이 모든 container low level 정보를 return 한다.
[devops@localhost ~]$ docker inspect nexus
[
{
"Id": "67826ba9e0179b6009c9c7a177fe1815fd320cdac65ea91d479413f7c4e5e81a",
"Created": "2019-06-26T03:19:12.069213873Z",
"Path": "sh",
"Args": [
"-c",
"${SONATYPE_DIR}/start-nexus-repository-manager.sh"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 19383,
"ExitCode": 0,
"Error": "",
"StartedAt": "2019-07-02T07:49:00.930407162Z",
"FinishedAt": "2019-07-02T07:48:08.216626691Z"
},
"Image": "sha256:36b0df681a47e5948f2088a446652766132141175dece2d6d47ef6e749385c05",
"ResolvConfPath": "/var/lib/docker/containers/67826ba9e0179b6009c9c7a177fe1815fd320cdac65ea91d479413f7c4e5e81a/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/67826ba9e0179b6009c9c7a177fe1815fd320cdac65ea91d479413f7c4e5e81a/hostname",
"HostsPath": "/var/lib/docker/containers/67826ba9e0179b6009c9c7a177fe1815fd320cdac65ea91d479413f7c4e5e81a/hosts",
"LogPath": "",
"Name": "/nexus",
"RestartCount": 0,
"Driver": "overlay2",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/nexus-data:/nexus-data"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "journald",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"8081/tcp": [
{
"HostIp": "",
"HostPort": "8081"
}
]
},
"RestartPolicy": {
"Name": "always",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": true,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": [
"label=disable"
],
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "docker-runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
},
"GraphDriver": {
"Name": "overlay2",
"Data": {
"LowerDir": "/var/lib/docker/overlay2/bdeae8fe832211ba5059562162cb4eb7098de60657f622a31f0115653c324301-init/diff:/var/lib/docker/overlay2/e3c7b24292cf5ea41f2d3ab9c3b91a3c3b22f09a1cb26cf6048b36802c30b036/diff:/var/lib/docker/overlay2/3f075ffc65dfb1a311d63c70842d0ba2c467ca9bf1289c5a2a45a21e77a8314c/diff:/var/lib/docker/overlay2/32e8540578f9058f575a9051bc28df2f0308da53a20469a3a91c1a6b60f9cb0e/diff",
"MergedDir": "/var/lib/docker/overlay2/bdeae8fe832211ba5059562162cb4eb7098de60657f622a31f0115653c324301/merged",
"UpperDir": "/var/lib/docker/overlay2/bdeae8fe832211ba5059562162cb4eb7098de60657f622a31f0115653c324301/diff",
"WorkDir": "/var/lib/docker/overlay2/bdeae8fe832211ba5059562162cb4eb7098de60657f622a31f0115653c324301/work"
}
},
"Mounts": [
{
"Type": "bind",
"Source": "/nexus-data",
"Destination": "/nexus-data",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "67826ba9e017",
"Domainname": "",
"User": "nexus",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"8081/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"SONATYPE_DIR=/opt/sonatype",
"NEXUS_HOME=/opt/sonatype/nexus",
"NEXUS_DATA=/nexus-data",
"NEXUS_CONTEXT=",
"SONATYPE_WORK=/opt/sonatype/sonatype-work",
"DOCKER_TYPE=docker",
"INSTALL4J_ADD_VM_PARAMS=-Xms1200m -Xmx1200m -XX:MaxDirectMemorySize=2g -Djava.util.prefs.userRoot=/nexus-data/javaprefs"
],
"Cmd": [
"sh",
"-c",
"${SONATYPE_DIR}/start-nexus-repository-manager.sh"
],
"ArgsEscaped": true,
"Image": "sonatype/nexus3",
"Volumes": {
"/nexus-data": {}
},
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"com.sonatype.license": "Apache License, Version 2.0",
"com.sonatype.name": "Nexus Repository Manager base image",
"org.label-schema.build-date": "20190305",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS",
"vendor": "Sonatype"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "50b3a078a453332680ca6dd09d2cd10fc641fddc49c5b3b34db178c516f8475d",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"8081/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8081"
}
]
},
"SandboxKey": "/var/run/docker/netns/50b3a078a453",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "b030c131340f1b86c3ce868dae109fee9814310503076f685ff274b42e76eeac",
"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": "e7bccaaf25cb4ba061b98aab2ef6470301c688b7d99db0f40e7e7bd7b6665379",
"EndpointID": "b030c131340f1b86c3ce868dae109fee9814310503076f685ff274b42e76eeac",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02"
}
}
}
}
]
여기서 특정 영역에 대한 정보만을 얻고 싶다면 다음과 같이 format 설정을 해주면 된다.
docker inspect --format
또는
docker inspect -f
를 사용하면 된다. 사용 법은 다음과 같다.
[devops@localhost ~]$ docker inspect --format='{{.NetworkSettings.Networks}}' nexus
map[bridge:0xc420130300]
inspect 해서 나온 모든 정보 중에서 필요로 하는 정보의 Name을 .Name.Name
식으로 표현 하면 특정 값을 얻어 낼 수가 있다. 가령 IPAddress
를 얻어 오고자 하면 다음과 같이 하면 된다.
[devops@localhost ~]$ docker inspect --format='{{.NetworkSettings.Networks.bridge.IPAddress}}' nexus
172.17.0.2
만약 해당 결과 값을 json 형태의 템플릿으로 받고자 하면 다음과 같이 하면 된다.
[devops@localhost ~]$ docker inspect --format='{{json .NetworkSettings.Networks.bridge.IPAddress}}' nexus "172.17.0.2"
""
앞뒤로 이와 같은게 붙은거 빼고는 차이가 없어 보이지만,
[devops@localhost ~]$ docker inspect --format='{{json .NetworkSettings.Networks}}' nexus
{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"e7bccaaf25cb4ba061b98aab2ef6470301c688b7d99db0f40e7e7bd7b6665379","EndpointID":"b030c131340f1b86c3ce868dae109fee9814310503076f685ff274b42e76eeac","Gateway":"172.17.0.1","IPAddress":"172.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:02"}}
Networks만을 출력하면 다른걸 확인 할 수있다. 앞서 json
없이 출력은 메모리 번지를 출력 했다면, json
과 함께 출력 하면 이하 모든 값이 string으로 출력 되는걸 확인 할 수 있다.
이외에
index
,range
,$variableParm 정의
,:=
Assignment 등이 추가로 잇는듯 한데 어떻게 사용하는지는 잘 모르겠다.
docker shell 로 바로 진입하기
docker run -it --rm <<이미지id>> /bin/sh
or
docker run -it --rm <<이미지id>> /bin/bash
or
docker run -it --rm --entrypoint /bin/bash <<이미지id>>
or
docker run -it --rm <<이미지id>> sh
or
docker run -it --rm --entrypoint sh <<이미지id>>
or
docker exec -it --rm <<이미지id>> /bin/sh or
docker exec -it --rm <<이미지id>> /bin/bash or
docker exec -it --rm --entrypoint /bin/bash <<이미지id>> or
docker exec -it --rm <<이미지id>> sh or
docker exec -it --rm --entrypoint sh <<이미지id>>
docker-compose 완전히 삭제하기
docker-compose down
docker rm -f $(docker ps -a -q)
docker volume rm $(docker volume ls -q)
docker-compose 시작
docker-compose up -d
여기서 -d는 background 실행이다.
Docker Volume
Docker가 Host PC의 Volume을 지나치게 먹을 때가 있다
$ df -h
파일 시스템 크기 사용 가용 사용% 마운트위치
tmpfs 3.1G 28M 3.1G 1% /run
/dev/sda1 907G 860G 683M 100% /
tmpfs 16G 52K 16G 1% /dev/shm
tmpfs 5.0M 16K 5.0M 1% /run/lock
/dev/sda2 221M 6.1M 215M 3% /boot/efi
tmpfs 3.1G 68K 3.1G 1% /run/user/1000
이런 경우에는 어디서 disk를 사용하는지 정확하게 알 필요가 있다
`docker system df`를 확인해 보면 Local Volumes에서 지나치게 많은 양의 디시크를 사용하고 있음을 확인 가능하다.
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 11 2 5.35GB 4.023GB (75%)
Containers 4 3 185B 182B (98%)
Local Volumes 37 4 876.3GB 268.6MB (0%)
Build Cache 0 0 0B 0B
더 상세하게 알아보자
$ docker system df -v
Images space usage:
REPOSITORY TAG IMAGE ID CREATED SIZE SHARED SIZE UNIQUE SIZE CONTAINERS
mysql latest f6360852d654 11 days ago 564.8MB 0B 564.8MB 1
restserver latest f2c153cb0e8c 2 weeks ago 470.1MB 455.9MB 14.23MB 0
javadocker2 latest 5f6a3f775da8 2 weeks ago 464MB 455.9MB 8.096MB 0
sdkperf latest cccdbeacb1fc 2 weeks ago 464MB 455.9MB 8.096MB 0
eclipse-temurin 17-jdk-jammy 3a958eff0206 4 weeks ago 455.9MB 455.9MB 0B 0
haproxy latest f48e4ec6d150 4 weeks ago 103.7MB 0B 103.7MB 0
solace/solace-pubsub-standard latest 32f63cd84dac 6 weeks ago 1.285GB 523.2MB 762.1MB 0
confluentinc/cp-kafka latest 8309da75aced 2 months ago 844.6MB 717.8MB 126.8MB 0
confluentinc/cp-zookeeper latest 5567928528f5 2 months ago 844.6MB 717.8MB 126.8MB 0 1.27GB 0
Containers space usage:
CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED STATUS NAMES
a64074eb1ae2 mysql "docker-entrypoint.s…" 1 182B 9 days ago Exited (255) 7 days ago mysql
Local Volumes space usage:
VOLUME NAME LINKS SIZE
06345bd01dbe7750c7dbd4b7ec74321e3e0bc7101eab09d97e04addb6adf22d2 0 67.11MB
1fb305b6a3b59bb6cb9793ff8b53826ccc4efe7094b5ea05d6cab80d7fb8120c 0 100B
339d39f47e6b0c604c17bf3de6af4ee78389e23613d1ae10a1866a7694fcf850 0 96B
cfae9b6964560aa744bace49e64c47ad71a2c687986912dd54a57d9ba546eeee 0 0B
1dd7436824f8cbfc93aae9424909f702b3480c024a82773a2d5208a356e6e945 0 96B
3e8df0253c3ce30bf00a320667dde7da24a69e6c468b113805a7d89938942272 0 100B
6c783159f68cccc4e01a27f5b24d6afacb9fefc9d18f30656a61dd231b95826e 0 0B
5e35be3d12eb7ee8e53c148d0a10f6abf3550e027a2fcf0219ebbef7a4564bf8 0 0B
8aa7abea8ef92a08fdb9f18f5389df04d8e497edb66d3d1b7374d2f5d72a07c7 0 0B
f99b7f80039cd36dda8211c6049db49cd1835b201215a69527195f9e97bc7e8d 0 8B
5791d37dfe55b4e4e17fc2bc54834813e0a537fe2b1c0f0e6cd81a335e08c419 0 0B
83efad96be18ef3ce5e7993bf9a4aab17b3e1050b4c13eb4925f8c353b496cb1 0 0B
abfe5a23ac5766dcfe8e060e1fe847b27601f68a8c7c515f9f4522cc15f1c1e5 0 0B
e0c229c8f79979e72bc0fe5fefe0fbca0ab8043c5fce4f8b167be779f1bd50b6 0 67.11MB
c038cefdc86f386b1389d339261d52b49df286be3ec2ee6dcf3d8b5fa555e812 0 458B
template_storage-group2 0 1.474GB
375d4ee4879cba91c18f4cd3a0a2bc61bb916221f433e31ba5089a45ee70205c 0 8B
648bade5e53a6197fcdafa5967b859c7b0577ceeca253111e85e9dbe5c156f7f 0 67.11MB
9491d07682339cae707db5bdf8ff1c873dde1d44c4d38e45435db9461b32e891 0 458B
ab1997c8a389b6bf38edb2f63072fe4c6239aea23d16f9089dbe2694a76e999c 0 96B
0490bb0a82f7e1097d8e1c337e8161563adadb31b57b25eb81b8c8cf3b3c799a 0 0B
07d90e41c38081dcc110e3c881f80f7513845f60daeb6a6951bdfbe3ba699510 0 0B
84f4d8d587447a130dc44bd99eec2f4f941957b7c392cc56d5e0485a327aa9b2 0 0B
d8c737551bf51aacb59a8f116f963f523a79df7599793e6441d4a68e7c6f6eae 0 0B
332a18fa7dba5fa3d615f97aadbbca5a24ce0273343724f0c38c3318aedd2989 0 96B
3695aabd55bc98245aef5a94ac222f2dd9e810cb228f2e830d96f67d1f1b0fc4 0 0B
6c07a26976903e83e5b54cc66fcecf3f263cde1429eecd08fd2e12c3e7981506 0 458B
a12e0c54790f6b8330f65b656c8af4ac5eb5423d993cea5bfb733765ed29c333 0 0B
891ba7f12e9a5ba196710334281a8330eb1bf4fc1a2f5d442f777a0a1f951a36 0 8B
c7c2049f87c61d588c0232c95ba262e755f4140dc135ff95bf113f9ea83a2820 0 0B
c7cf3e8b1e70d1633ddfca82549c8a5337bbce4c07afd827734139ef3c3fdb26 1 209.4MB
template_storage-group1 0 873GB
0edde1674b046452c51a8310fea3a34cdd221fae1bdb7c7b3467434c3b66ec41 0 458B
2ea3a2f3fe4dd66e46a99cdfa5ae512315a570cfb38333cee0e7bad3771869d5 0 67.11MB
67e88becb22b06953719289772d52b38014867c204d329d1df27c08af233a8c5 0 137.5kB
745241baacab3f1fe2fddddb22070ef46157199662f7c107869f0fa192ea5c32 0 0B
template_storage-group3 0 1.318GB
Build cache usage: 0B
CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
template_storage-group1 0 873GB
이 너무 많은 데이터를 저장하고 있다. 일반적으로 그러면 안되지만 과감하게 해당 볼륨을 삭제 하자.
물론 그전에 작동중인 컨테이너는 중지하자.
$ docker volume rm template_storage-group1
template_storage-group1
사용율이 6%로 내려온 것을 확인 할 수 있다
$ df -h
파일 시스템 크기 사용 가용 사용% 마운트위치
tmpfs 3.1G 28M 3.1G 1% /run
/dev/sda1 907G 47G 814G 6% /
tmpfs 16G 52K 16G 1% /dev/shm
tmpfs 5.0M 16K 5.0M 1% /run/lock
/dev/sda2 221M 6.1M 215M 3% /boot/efi
tmpfs 3.1G 68K 3.1G 1% /run/user/1000
'Software활용' 카테고리의 다른 글
Jenkins with tomcat (0) | 2020.03.27 |
---|---|
Jenkins on centos7 (0) | 2020.03.27 |
Jenkins Basic (0) | 2020.03.27 |
wildfly (Jboss AS) installation with Postgresql driver on Mac (0) | 2020.03.27 |
Redis & Jedis (0) | 2020.03.27 |