为什么我不能ping泊坞容器?

时间:2017-06-28 18:32:01

标签: networking docker

不要将其标记为重复,因为我查看了其他答案,但它并没有解决我的问题。

我正在使用Windows 7和docker工具箱。

我正在做这个教程: https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/microservices

所以在这个命令之后:

docker run -d -p 80:5000 --name hello-docker weather-microservice

我无法联系到http://localhost/

因此,为了解决问题,我决定对该框进行ping操作。但我不能。

$ docker ps
CONTAINER ID    IMAGE                   COMMAND                 CREATED         STATUS      PORTS                   NAMES
78179117b516    weather-microservice    "dotnet out/Weathe..."  18 hours ago    Up 18 hours 0.0.0.0:80->5000/tcp    hello-docker

以下不起作用:

$ docker-machine ip weather-microservice
Host does not exist: "weather-microservice"

$ docker-machine ip hello-docker
Host does not exist: "hello-docker"

$ docker-machine ip 78179117b516
Host does not exist: "78179117b516"

$ docker inspect 78179117b516
[
    {
        "Id": "78179117b516332c61e393a36cc10f33e0f0b0d2f418d8483b79f90207e0de3c",
        "Created": "2017-06-27T23:37:12.147696044Z",
        "Path": "dotnet",
        "Args": [
            "out/WeatherMicroservice.dll",
            "--server.urls",
            "http://0.0.0.0:5000"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 22059,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-06-27T23:37:12.339014063Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:0f6481b4a6fb864ecddb36c48a9facfbe30801d328daf59926e1c6c642f3ae24",
        "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/78179117b516332c61e393a36cc10f33e0f0b0d2f418d8483b79f90207e0de3c/resolv.conf",
        "HostnamePath": "/mnt/sda1/var/lib/docker/containers/78179117b516332c61e393a36cc10f33e0f0b0d2f418d8483b79f90207e0de3c/hostname",
        "HostsPath": "/mnt/sda1/var/lib/docker/containers/78179117b516332c61e393a36cc10f33e0f0b0d2f418d8483b79f90207e0de3c/hosts",
        "LogPath": "/mnt/sda1/var/lib/docker/containers/78179117b516332c61e393a36cc10f33e0f0b0d2f418d8483b79f90207e0de3c/78179117b516332c61e393a36cc10f33e0f0b0d2f418d8483b79f90207e0de3c-json.log",
        "Name": "/hello-docker",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "5000/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ]
            },
            "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": "runc",
            "ConsoleSize": [
                25,
                80
            ],
            "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": [],
            "DeviceCgroupRules": null,
            "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": {
            "Data": null,
            "Name": "aufs"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "78179117b516",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "5000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "DOTNET_SDK_VERSION=1.0.0-rc4-004771",
                "DOTNET_SDK_DOWNLOAD_URL=https://dotnetcli.blob.core.windows.net/dotnet/Sdk/1.0.0-rc4-004771/dotnet-dev-debian-x64.1.0.0-rc4-004771.tar.gz",
                "NUGET_XMLDOC_MODE=skip"
            ],
            "Cmd": null,
            "ArgsEscaped": true,
            "Image": "weather-microservice",
            "Volumes": null,
            "WorkingDir": "/app",
            "Entrypoint": [
                "dotnet",
                "out/WeatherMicroservice.dll",
                "--server.urls",
                "http://0.0.0.0:5000"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "f1b934a02a8ac2e83bf68485d2dfb138b859d1e7b3beb4cb7ba966c9e3f4befa",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "5000/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/f1b934a02a8a",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "9c555071437b1919db7c539f0bd3946b7a32f92dcf49c684dbbe01e0592b9af5",
            "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": "6226280f22a5aaaa50c60d6f1a19ae8f7243bb79634c4394f62b21a10a868e48",
                    "EndpointID": "9c555071437b1919db7c539f0bd3946b7a32f92dcf49c684dbbe01e0592b9af5",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02"
                }
            }
        }
    }
]

所以当我这样做时:

$ ping 172.17.0.2

Pinging 172.17.0.2 with 32 bytes of data:
Request timed out.

这有效:

$ docker exec -it 78179117b516 ping www.google.com
PING www.google.com (172.217.3.196): 56 data bytes
64 bytes from 172.217.3.196: icmp_seq=0 ttl=53 time=5.412 ms

我做错了什么或我错过了什么?

5 个答案:

答案 0 :(得分:6)

这是因为,您通过docker inspect命令看到的IP地址被docker用于内部网络和通信。它无法从外部访问。此外,localhost将无法工作,因为您正在运行在ubuntu VM中运行的docker工具箱。您必须首先获取VM的IP地址,

docker-machine ls

如果我的内存正常,并且工具箱在Mac和Windows中的工作方式相同,则IP地址应为192.168.99.100。因此,您可以通过http://192.168.99.100访问自己的应用。除了这些之外,为什么还在使用泊坞工具箱。新方法是用于windows的mac / docker的docker。这样更容易,更有效率。首先,您将能够通过localhost访问您的应用程序,而无需知道IP地址。

答案 1 :(得分:4)

实际上,我从Control Panel \ Network和Internet \ Network Connections获得了我的容器的IP。有一个名为vEthernet(DockerNAT)的适配器,它是容器的适配器。我可以ping我找到的适配器的IP。

答案 2 :(得分:2)

Docker Known Limitations中所述:

用于Windows的Docker桌面无法将流量路由到Linux容器。但是,您可以ping Windows容器。

因此,当尝试从Windows主机到Linux容器ping容器时,请记住这一点。您可能想使用publish的{​​{1}}功能来启用端口转发

答案 3 :(得分:1)

10次中的9次,它是Windows防火墙。

完全禁用Windows防火墙 - 将其关闭 - 看看是否可以访问您的网站。

答案 4 :(得分:0)

类似于Ehsan Mirsaeedi所说的,但对我来说,正确的选择是vEthernet(默认交换机)。还在Windows docker container cannot ping host

上发布了带有图片的答案

希望这对其他人有帮助!