java面试题网站:www.javaoffers.com
在启动docker容器时,有可能一些参数写错了,或则在某些场景下我们需要修改容器的启动的参数,这时我们可以直接去修改容器启动的参数文件中的数据即可.
容器启动参数参数的位置: /var/lib/docker/containers/
root@cmj-Inspiron-7590:/home/cmj# cd /var/lib/docker/containers/
root@cmj-Inspiron-7590:/var/lib/docker/containers# ll
总用量 68
drwx------ 17 root root 4096 8月 23 17:21 ./
drwx--x--x 14 root root 4096 8月 23 16:33 ../
drwx------ 4 root root 4096 8月 23 16:33 0f3b89877b1b886b14ae74e1cf208eecdf0fde4899ae5b911ff78cc2bfa53ab2/
drwx------ 4 root root 4096 8月 23 16:33 197b16756c753cab2ffcea0ecc69c24ac8b5b19551afde57f2ea444be087643d/
drwx------ 4 root root 4096 8月 23 16:37 24c1902868301102f7dad95433345f354a675bfc15dfd37d9888957418c89bfe/
drwx------ 4 root root 4096 8月 23 16:33 55fa1170f16aaf5797b881c06067227f49e31d1d196972482803b74a7d44b1d4/
drwx------ 4 root root 4096 8月 23 16:37 5e3adacf8b40f9053f55b9030bbef28a7cc4dd4a36a87b5a1a461ebad4cf6a2a/
drwx------ 4 root root 4096 8月 23 16:33 666d2662f908ccf050dfdb48b3f2b7054f65733b3f1f660e696d2bcd3a0fe550/
drwx------ 4 root root 4096 8月 23 16:33 740cc1f951790495004cd6199da4ac8fd27400df036f7bb5120ae4a2625d1fa8/
drwx------ 4 root root 4096 8月 23 16:33 a6876dde4cf2cdd204f3c85636886f8f754b08dce611496d5f974f732e1b00eb/
drwx------ 4 root root 4096 8月 23 16:36 b3d992745c250fa68671be04f99bb919fa40e89a6c85d3fd6de504d8f2cc1356/
drwx------ 4 root root 4096 8月 23 17:20 b63ce2aa7cc8584b70e4ca61f9719c44590ad1c1777f05e01791fafdc33f38c5/
drwx------ 4 root root 4096 8月 23 16:33 c8d76794f22caf6b6a77531afaf2b27c30ac1c16844fcdf385c5688266dad416/
drwx------ 4 root root 4096 8月 23 16:33 d51f87db3987dbd09d2b8f79bd94e416ac28e088edcddcd9c4480a5725f6676d/
drwx------ 4 root root 4096 8月 23 16:33 df6d91ea7525967050d0255af0962b1c1f6b08a86d0cb914b01d2545a6eff847/
drwx------ 4 root root 4096 8月 23 16:33 e69196affff7f007e88808d84fe3468ee775fd4a5d7c8dde116b53ab9cbfc6b1/
drwx------ 4 root root 4096 8月 23 16:33 f2508a0b17eab64dbc7c5b6dcbbae03efd944d752ca4dd4728b553b559d6bd0d/
查看容器id
root@cmj-Inspiron-7590:/var/lib/docker/containers# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
55fa1170f16a docker.elastic.co/kibana/kibana:7.9.0 "/usr/local/bin/dumb…" 3 days ago Exited (0) 2 hours ago kibana7.9
197b16756c75 docker.elastic.co/elasticsearch/elasticsearch:7.9.0 "/tini -- /usr/local…" 3 days ago Exited (143) 2 hours ago es7.9
b63ce2aa7cc8 docker.elastic.co/kibana/kibana:6.0.1 "/bin/bash /usr/loca…" 10 days ago Up 46 minutes 0.0.0.0:5601->5601/tcp kibana
b3d992745c25 docker.elastic.co/elasticsearch/elasticsearch:6.0.1 "/usr/local/bin/dock…" 13 days ago Up 2 hours 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp es
666d2662f908 registry.cn-qingdao.aliyuncs.com/metersphere/jmeter-master:0.0.6 "/bin/sh -c /run-tes…" 5 weeks ago Exited (137) 5 weeks ago 6206511b-8ea2-4c1e-9c9a-f3bc5832c731-0
c8d76794f22c registry.cn-qingdao.aliyuncs.com/metersphere/metersphere:v1.0.3 "/deployments/run-ja…" 5 weeks ago Exited (143) 5 weeks ago ms-server
5e3adacf8b40 registry.cn-qingdao.aliyuncs.com/metersphere/ms-data-streaming:v1.0.3 "/deployments/run-ja…" 5 weeks ago Exited (143) About an hour ago ms-data-streaming
24c190286830 registry.cn-qingdao.aliyuncs.com/metersphere/kafka:2 "/opt/bitnami/script…" 5 weeks ago Exited (1) About an hour ago kafka
df6d91ea7525 registry.cn-qingdao.aliyuncs.com/metersphere/ms-node-controller:v1.0.3 "/deployments/run-ja…" 5 weeks ago Exited (143) 5 weeks ago ms-node-controller
e69196affff7 registry.cn-qingdao.aliyuncs.com/metersphere/mysql:5.7.25 "docker-entrypoint.s…" 5 weeks ago Exited (0) 5 weeks ago mysql
f2508a0b17ea registry.cn-qingdao.aliyuncs.com/metersphere/zookeeper:3 "/opt/bitnami/script…" 5 weeks ago Exited (143) 3 weeks ago zookeeper
740cc1f95179 a2218a3d7cfb "/home/udr/run.sh" 7 weeks ago Exited (143) 7 weeks ago laughing_brattain
d51f87db3987 mysql:5.6.40 "docker-entrypoint.s…" 7 weeks ago Exited (0) 7 weeks ago mysql5.6
a6876dde4cf2 docker.elastic.co/elasticsearch/elasticsearch:6.0.1 "/usr/local/bin/dock…" 2 months ago Exited (143) 2 months ago tender_curran
0f3b89877b1b mysql:5.7 "docker-entrypoint.s…" 2 months ago Exited (0) 2 months ago mysql5.7
root@cmj-Inspiron-7590:/var/lib/docker/containers#
CONTAINER ID 代表容器id, 对应containers 目录下的文件,例如 24c190286830 对应 24c1902868301102f7dad95433345f354a675bfc15dfd37d9888957418c89bfe
进入容器24c190286830的配置目录
root@cmj-Inspiron-7590:/var/lib/docker/containers# cd 24c1902868301102f7dad95433345f354a675bfc15dfd37d9888957418c89bfe/
root@cmj-Inspiron-7590:/var/lib/docker/containers/24c1902868301102f7dad95433345f354a675bfc15dfd37d9888957418c89bfe# ll
总用量 262252
drwx------ 4 root root 4096 8月 23 16:37 ./
drwx------ 17 root root 4096 8月 23 17:21 ../
-rw-r----- 1 root root 268490531 8月 23 16:37 24c1902868301102f7dad95433345f354a675bfc15dfd37d9888957418c89bfe-json.log
drwx------ 2 root root 4096 7月 17 16:31 checkpoints/
-rw------- 1 root root 5239 8月 23 16:37 config.v2.json
-rw-r--r-- 1 root root 1578 8月 23 16:37 hostconfig.json
-rw-r--r-- 1 root root 13 8月 23 16:37 hostname
-rw-r--r-- 1 root root 150 8月 23 16:37 hosts
drwx------ 3 root root 4096 7月 17 16:31 mounts/
-rw-r--r-- 1 root root 38 8月 23 16:37 resolv.conf
-rw-r--r-- 1 root root 71 8月 23 16:37 resolv.conf.hash
查看启动配置信息
root@cmj-Inspiron-7590:/var/lib/docker/containers/24c1902868301102f7dad95433345f354a675bfc15dfd37d9888957418c89bfe# more hostconfig.json
{"Binds":["metersphere_ms-kafka-data:/bitnami:rw"],"ContainerIDFile":"","LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"metersphere_ms-network","PortBindings":{"19092/tcp":[{"HostIp":"","HostPort":"19092"}]},"RestartPolicy":{"
Name":"on-failure","MaximumRetryCount":0},"AutoRemove":false,"VolumeDriver":"","VolumesFrom":[],"CapAdd":null,"CapDrop":null,"Capabilities":null,"Dns":[],"DnsOptions":[],"DnsSearch":[],"ExtraHosts":null,"GroupAdd":null,"IpcMode":"shareabl
e","Cgroup":"","Links":[],"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":null,"BlkioDeviceReadBps":null,"BlkioDeviceWriteBps":null,"BlkioDeviceReadIOps":null,"BlkioDeviceWriteIOps":null,"CpuPeriod":0,"CpuQuota":0,"Cpu
RealtimePeriod":0,"CpuRealtimeRuntime":0,"CpusetCpus":"","CpusetMems":"","Devices":null,"DeviceCgroupRules":null,"DeviceRequests":null,"KernelMemory":0,"KernelMemoryTCP":0,"MemoryReservation":0,"MemorySwap":0,"MemorySwappiness":null,"OomK
illDisable":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/t
imer_stats","/proc/sched_debug","/proc/scsi","/sys/firmware"],"ReadonlyPaths":["/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]}
root@cmj-Inspiron-7590:/var/lib/docker/containers/24c1902868301102f7dad95433345f354a675bfc15dfd37d9888957418c89bfe#
例如我们想把容器启动改为伴随docker服务自动启动
修改Name为always即可
"RestartPolicy":{"Name":"always","MaximumRetryCount":0}
你也可以写改其他参数,例如绑定的端口, 容器别名等等.