一、查看容器IP地址
我们可以通过以下命令查看容器运行的各种数据
docker inspect mycentos2
注:此命令需要在宿主机上执行,容器内部无效。
也可以直接执行下面的命令直接输出IP地址(只是格式化,对提取的信息进行筛选而已):
docker inspect --format='{{.NetworkSettings.IPAddress}}' mycentos2
获取其他信息,同理
执行:
docker inspect mycentos2
后的所有内容:
[
{
"Id": "33c17a8f35f3485c36d2ade49ce6031fae17858d9f68bd1c6bd935ef705bae6b",
"Created": "2019-05-28T02:12:09.566442443Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 8160,
"ExitCode": 0,
"Error": "",
"StartedAt": "2019-05-28T02:23:00.019357024Z",
"FinishedAt": "2019-05-28T02:20:32.937194145Z"
},
"Image": "sha256:196e0ce0c9fbb31da595b893dd39bc9fd4aa78a474bbdc21459a3ebe855b7768",
"ResolvConfPath": "/var/lib/docker/containers/33c17a8f35f3485c36d2ade49ce6031fae17858d9f68bd1c6bd935ef705bae6b/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/33c17a8f35f3485c36d2ade49ce6031fae17858d9f68bd1c6bd935ef705bae6b/hostname",
"HostsPath": "/var/lib/docker/containers/33c17a8f35f3485c36d2ade49ce6031fae17858d9f68bd1c6bd935ef705bae6b/hosts",
"LogPath": "",
"Name": "/mycentos2",
"RestartCount": 0,
"Driver": "devicemapper",
"MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c48,c856",
"ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c48,c856",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "journald",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"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": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"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": "devicemapper",
"Data": {
"DeviceId": "68",
"DeviceName": "docker-253:0-674-4d8f81920fd42d490ccbd45545e81559f24b4deb33befb56a22b324e0ed5340f",
"DeviceSize": "10737418240"
}
},
"Mounts": [],
"Config": {
"Hostname": "33c17a8f35f3",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": true,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "centos:7",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"build-date": "20170911",
"license": "GPLv2",
"name": "CentOS Base Image",
"vendor": "CentOS"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "0195890a89ca6f5b49618f6764d6c5e86bf83bf9a3ee83d9da867953ef43e095",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/0195890a89ca",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "7a0db1e9049d5b0cfd698a2dd9b7e0658f7e97e9b619a4760d99c1f0be31e72b",
"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": "b4ba16aa4cdc7e7f05d20177d42f366dafbd03b4ee878b0a97ba2850375a4c34",
"EndpointID": "7a0db1e9049d5b0cfd698a2dd9b7e0658f7e97e9b619a4760d99c1f0be31e72b",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02"
}
}
}
}
]
相关参考:https://blog.csdn.net/weixin_40816738/category_9289461.html