通过如下的 docker-compose.yaml
启动一个 rabbitmq
version: "3.7"
services:
rabbitmq3-management:
restart: always
container_name: rabbitmq3-management
image: rabbitmq:3-management
hostname: rabbitmq3-management-standalone
logging:
driver: json-file
options:
max-size: "100m"
max-file: "1"
environment:
- RABBITMQ_DEFAULT_USER=pon
- RABBITMQ_DEFAULT_PASS=pon
volumes:
# - "./volumes:/var/lib/rabbitmq"
- "./rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf"
ports:
- "5672:5672"
- "15672:15672"
- "15692:15692"
然后使用 docker inspect rabbitmq3-management
查看容器信息
[
{
"Id": "c30c681cbe27d303af309bc3acd546833a9aeadbfed10761a57b642e29a3ec72",
"Created": "2022-07-31T08:21:20.053832177Z",
"Path": "docker-entrypoint.sh",
"Args": [
"rabbitmq-server"
],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 0,
"Error": "",
"StartedAt": "2022-09-24T13:45:49.215719798Z",
"FinishedAt": "2022-10-31T06:58:24.273140419Z"
},
"Image": "sha256:13f1d0a135aa88413c2e3fa3b3a3de335c8204ba32adfc0f47120230b4852713",
"ResolvConfPath": "/var/lib/docker/containers/c30c681cbe27d303af309bc3acd546833a9aeadbfed10761a57b642e29a3ec72/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/c30c681cbe27d303af309bc3acd546833a9aeadbfed10761a57b642e29a3ec72/hostname",
"HostsPath": "/var/lib/docker/containers/c30c681cbe27d303af309bc3acd546833a9aeadbfed10761a57b642e29a3ec72/hosts",
"LogPath": "/var/lib/docker/containers/c30c681cbe27d303af309bc3acd546833a9aeadbfed10761a57b642e29a3ec72/c30c681cbe27d303af309bc3acd546833a9aeadbfed10761a57b642e29a3ec72-json.log",
"Name": "/rabbitmq3-management",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/home/bot/opt/docker-compose-public/rabbit/volumes:/var/lib/rabbitmq:rw"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {
"max-file": "1",
"max-size": "100m"
}
},
"NetworkMode": "rabbit_default",
"PortBindings": {
"15672/tcp": [
{
"HostIp": "",
"HostPort": "15672"
}
],
"5672/tcp": [
{
"HostIp": "",
"HostPort": "5672"
}
]
},
"RestartPolicy": {
"Name": "",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"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": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"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/501eeca753155e28257bd2b19dd7b95814807bf39d96eb005c37a9934df00430-init/diff:/var/lib/docker/overlay2/96c2738ddce886102b2d30ea6c3eb9e332ba96bdc91e998f6bfce4eb0e299319/diff:/var/lib/docker/overlay2/7a6b805d6d56e83352b7b28e0661585338e173c7f8e45adfa824112448604e1b/diff:/var/lib/docker/overlay2/59ff0ae17874980d1f591690f58c25ef21cbd53fd7a1d7c211da569593ab6fcf/diff:/var/lib/docker/overlay2/86e1ff071baece97b956f096b2c237202106935ad31b8aa7eed71a7c7f45335e/diff:/var/lib/docker/overlay2/24385ba4bd26c27c6c581fbe95635dea1739b377585c7d22d69420d89b9e5f49/diff:/var/lib/docker/overlay2/ce0e163dcf8be3164be70f3f7cb746af4ef8af3e8cb0c2b350e06edc29e1f6b9/diff:/var/lib/docker/overlay2/b722250773268c01e280b799b9a5cc335a711b5fc24bcf05562fccc3e8753541/diff:/var/lib/docker/overlay2/f3d85ca913cdb62f197e08262c201dd9502d11a7c63b662e7f9aff892535ff9f/diff:/var/lib/docker/overlay2/1143b67fe9b6fec0c0be1b8233356c073268f3bb5714cf2b8ade8a4b234afdb2/diff:/var/lib/docker/overlay2/86dabdb83dd77a60c5b0f1e28e2e00680c033ffe8f54db61afa7678f6f7eb128/diff",
"MergedDir": "/var/lib/docker/overlay2/501eeca753155e28257bd2b19dd7b95814807bf39d96eb005c37a9934df00430/merged",
"UpperDir": "/var/lib/docker/overlay2/501eeca753155e28257bd2b19dd7b95814807bf39d96eb005c37a9934df00430/diff",
"WorkDir": "/var/lib/docker/overlay2/501eeca753155e28257bd2b19dd7b95814807bf39d96eb005c37a9934df00430/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/home/bot/opt/docker-compose-public/rabbit/volumes",
"Destination": "/var/lib/rabbitmq",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "rabbitmq3-management-master",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"15671/tcp": {},
"15672/tcp": {},
"15691/tcp": {},
"15692/tcp": {},
"25672/tcp": {},
"4369/tcp": {},
"5671/tcp": {},
"5672/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"RABBITMQ_DEFAULT_USER=pon",
"RABBITMQ_DEFAULT_PASS=pon",
"PATH=/opt/rabbitmq/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"OPENSSL_VERSION=1.1.1q",
"OPENSSL_SOURCE_SHA256=d7939ce614029cdff0b6c20f0e2e5703158a489a72b2507b8bd51bf8c8fd10ca",
"OPENSSL_PGP_KEY_IDS=0x8657ABB260F056B1E5190839D9C4D26D0E604491 0x5B2545DAB21995F4088CEFAA36CEE4DEB00CFE33 0xED230BEC4D4F2518B9D7DF41F0DB4D21C1D35231 0xC1F33DD8CE1D4CC613AF14DA9195C48241FBF7DD 0x7953AC1FBC3DC8B3B292393ED5E9E43F7DF9EE8C 0xE5E52560DD91C556DDBDA5D02064C53641C25E5D",
"OTP_VERSION=24.3.4.2",
"OTP_SOURCE_SHA256=0376d50f867a29426d47600056e8cc49c95b51ef172b6b9030628e35aecd46af",
"RABBITMQ_DATA_DIR=/var/lib/rabbitmq",
"RABBITMQ_VERSION=3.10.6",
"RABBITMQ_PGP_KEY_ID=0x0A9AF2115F4687BD29803A206B73A36E6026DFCA",
"RABBITMQ_HOME=/opt/rabbitmq",
"HOME=/var/lib/rabbitmq",
"LANG=C.UTF-8",
"LANGUAGE=C.UTF-8",
"LC_ALL=C.UTF-8"
],
"Cmd": [
"rabbitmq-server"
],
"Image": "rabbitmq:3-management",
"Volumes": {
"/var/lib/rabbitmq": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "09e3dacf5df850ccfb36a36e255b01fa45323074b605ceaf22fa846b7ed39134",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "rabbit",
"com.docker.compose.project.config_files": "docker-compose.yaml",
"com.docker.compose.project.working_dir": "/home/bot/opt/docker-compose-public/rabbit",
"com.docker.compose.service": "rabbitmq3-management",
"com.docker.compose.version": "1.25.0"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "aeedd25dc2d1bf676512bca9b9e74cce42eaf5d815f0afdfcfa32d812ee0830e",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/aeedd25dc2d1",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"rabbit_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"rabbitmq3-management",
"c30c681cbe27",
"rabbitmq3-management-master"
],
"NetworkID": "b40ffa70882f415bc43f21c0489b25b0f2c2fc4d74ff07fd0fdbca97c842fbe5",
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null
}
}
}
}
]
可以看到这里的网络类型是 rabbit_default
而不是 bridge、none、container、host 四者中的任意一个
docker 容器的网络模式
为什么?
我知道了,参考如何查看container工作在哪种网络模式
docker-compose.yaml 里面的 network_mode 只是 alias name,而不是 type name
要看一个容器用的是哪个类型的网络,需要使用
docker network ls
可以看到我们的 rabbitmq3-management 的 network name 是 rabbit_default,network DRIVER 是 bridge