#Linux里查看本机ip地址 ip addr ifconfig
[root@VM-16-5-centos /]# ip addr (或者ifconfig) 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 52:54:00:3f:4f:1c brd ff:ff:ff:ff:ff:ff inet 10.0.16.5/22 brd 10.0.19.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::5054:ff:fe3f:4f1c/64 scope link valid_lft forever preferred_lft forever 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:d2:14:5c:09 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever inet6 fe80::42:d2ff:fe14:5c09/64 scope link valid_lft forever preferred_lft forever #测试是否能ping通docker0 [root@VM-16-5-centos /]# ping 172.17.0.1 PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data. 64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.039 ms 64 bytes from 172.17.0.1: icmp_seq=2 ttl=64 time=0.041 ms 64 bytes from 172.17.0.1: icmp_seq=3 ttl=64 time=0.042 ms 64 bytes from 172.17.0.1: icmp_seq=4 ttl=64 time=0.036 ms ^C --- 172.17.0.1 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3000ms rtt min/avg/max/mdev = 0.036/0.039/0.042/0.006 ms
#查看tomcat容器相关信息 [root@VM-16-5-centos /]# docker inspect dcf25e61c138 [ { "Id": "dcf25e61c13894a0d61870fcc1ad6a4cefcb531b00e9cd5fec5f7d54971d6871", "Created": "2023-02-13T06:32:31.773322109Z", "Path": "catalina.sh", "Args": [ "run" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 19517, "ExitCode": 0, "Error": "", "StartedAt": "2023-02-18T09:58:54.860637695Z", "FinishedAt": "2023-02-13T08:05:53.824258946Z" }, "Image": "sha256:b07e16b110887760e9f0a7e2d55c9a64c1d605309bddcd56c95749c91513d451", "ResolvConfPath": "/var/lib/docker/containers/dcf25e61c13894a0d61870fcc1ad6a4cefcb531b00e9cd5fec5f7d54971d6871/resolv.conf", "HostnamePath": "/var/lib/docker/containers/dcf25e61c13894a0d61870fcc1ad6a4cefcb531b00e9cd5fec5f7d54971d6871/hostname", "HostsPath": "/var/lib/docker/containers/dcf25e61c13894a0d61870fcc1ad6a4cefcb531b00e9cd5fec5f7d54971d6871/hosts", "LogPath": "/var/lib/docker/containers/dcf25e61c13894a0d61870fcc1ad6a4cefcb531b00e9cd5fec5f7d54971d6871/dcf25e61c13894a0d61870fcc1ad6a4cefcb531b00e9cd5fec5f7d54971d6871-json.log", "Name": "/tomcat01", "RestartCount": 0, "Driver": "overlay2", "Platform": "linux", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": { "8080/tcp": [ { "HostIp": "", "HostPort": "3355" } ] }, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "ConsoleSize": [ 25, 179 ], "CapAdd": null, "CapDrop": null, "CgroupnsMode": "host", "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", "Isolation": "", "CpuShares": 0, "Memory": 0, "NanoCpus": 0, "CgroupParent": "", "BlkioWeight": 0, "BlkioWeightDevice": [], "BlkioDeviceReadBps": [], "BlkioDeviceWriteBps": [], "BlkioDeviceReadIOps": [], "BlkioDeviceWriteIOps": [], "CpuPeriod": 0, "CpuQuota": 0, "CpuRealtimePeriod": 0, "CpuRealtimeRuntime": 0, "CpusetCpus": "", "CpusetMems": "", "Devices": [], "DeviceCgroupRules": null, "DeviceRequests": null, "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/db58e0d55834b31ce6ef1e6e863fba188007e89f75a5b09597ac6fbcdbea8200-init/diff:/var/lib/docker/overlay2/ccdc5b6b5149fe15f86dbd7b223526471bd34b54adf2712dc516b8dfb47adb25/diff:/var/lib/docker/overlay2/d66bc61537a6126992e4e1de75b93bc9445864fd88e9b076834e72d04a928e70/diff:/var/lib/docker/overlay2/b75495e5bde09db6fd8735152a8c38fea408aa8aff1d1ebd07368e01e10c76fc/diff:/var/lib/docker/overlay2/e5105d9a6b73d9cce4b26ce79a7b7516189896aa6f78c3a0f2b37b571d753da8/diff:/var/lib/docker/overlay2/ce6466763d59debae0c1d1cbce8163318efb5dd385c5e79ef356610ffc9b9b93/diff:/var/lib/docker/overlay2/c22ea8305a7dc3d9536ea9cc8e922192e5b665c09424e2072feb589bce9c5a66/diff:/var/lib/docker/overlay2/63d30096d984ac8e42aafbc726d4907d7e1f8c3e4aeb63fc5e2df77783258548/diff", "MergedDir": "/var/lib/docker/overlay2/db58e0d55834b31ce6ef1e6e863fba188007e89f75a5b09597ac6fbcdbea8200/merged", "UpperDir": "/var/lib/docker/overlay2/db58e0d55834b31ce6ef1e6e863fba188007e89f75a5b09597ac6fbcdbea8200/diff", "WorkDir": "/var/lib/docker/overlay2/db58e0d55834b31ce6ef1e6e863fba188007e89f75a5b09597ac6fbcdbea8200/work" }, "Name": "overlay2" }, "Mounts": [], "Config": { "Hostname": "dcf25e61c138", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "8080/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/tomcat/bin:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "JAVA_HOME=/opt/java/openjdk", "LANG=en_US.UTF-8", "LANGUAGE=en_US:en", "LC_ALL=en_US.UTF-8", "JAVA_VERSION=jdk-17.0.6+10", "CATALINA_HOME=/usr/local/tomcat", "TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib", "LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib", "GPG_KEYS=48F8E69F6390C9F25CFEDCD268248959359E722B A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243", "TOMCAT_MAJOR=9", "TOMCAT_VERSION=9.0.71", "TOMCAT_SHA512=6a747e68eff4b68a8defba111103ef6b1606030c180143de0419d015052a5567fca1a86e3d3e058a10246c02b98e89431e9344f80475189573fa0d5c70bfb4cb" ], "Cmd": [ "catalina.sh", "run" ], "Image": "tomcat:9.0", "Volumes": null, "WorkingDir": "/usr/local/tomcat", "Entrypoint": null, "OnBuild": null, "Labels": { "org.opencontainers.image.ref.name": "ubuntu", "org.opencontainers.image.version": "22.04" } }, "NetworkSettings": { "Bridge": "", "SandboxID": "f61dadfb0c6776bad36a53022bd2eeaa50ce4146618d34d921268c594658eb88", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": { "8080/tcp": [ { "HostIp": "0.0.0.0", "HostPort": "3355" }, { "HostIp": "::", "HostPort": "3355" } ] }, "SandboxKey": "/var/run/docker/netns/f61dadfb0c67", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "516a547df47472023b78d73c1a9fe9fdf2bfbcac22bd7b75c391cea567ac750f", "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": "6fd7bb30e2a8bb6aa470d07f4e98f89c9d0bcbb1f48c60b40f53b2774b4da720", "EndpointID": "516a547df47472023b78d73c1a9fe9fdf2bfbcac22bd7b75c391cea567ac750f", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:02", "DriverOpts": null } } } } ]
#测试是否能ping通正在运行的tomcat容器 [root@VM-16-5-centos /]# ping 172.17.0.2 PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data. 64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.055 ms 64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.032 ms 64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.032 ms 64 bytes from 172.17.0.2: icmp_seq=4 ttl=64 time=0.043 ms ^C --- 172.17.0.2 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3000ms rtt min/avg/max/mdev = 0.032/0.040/0.055/0.011 ms
#linux可以ping通docker容器内部,因为我们每启动一个docker容器,docker就会给docker容器分配一个ip,我们只要安装了docker,就会有一个网卡docker0,桥接模式,使用veth-pair技术;
|