Docker 容器没有默认网关

Docker 容器没有默认网关

我正在 Windows Server 2016 上测试 Docker(1.12.2-cs2-ws-beta,内部版本 050b611),但无法连接到容器。我意识到我的容器没有分配默认网关。如何让我的容器获取默认网关?

检查NAT网络,已提供默认网关:

PS C:\Users\Administrator> docker network inspect 32ccb769f85a    
[
        {
            "Name": "nat",
            "Id": "32ccb769f85ac73c317066dbe29f8c7cbf41b784c3dca6be9ac496285ae39d76",
            "Scope": "local",
            "Driver": "nat",
            "EnableIPv6": false,
            "IPAM": {
                "Driver": "default",
                "Options": null,
                "Config": [
                    {
                        "Subnet": "172.20.128.0/20",
                        "Gateway": "172.20.128.1"
                    }
                ]
            },
            "Internal": false,
            "Attachable": false,
            "Containers": {
                "4cd832e9b613d0756af4d85e895d5e01af7f7afe4710ba3229e056d9955e1c75": {
                    "Name": "webappbasic1-task-5d5c5892-1ff2-bc18-72ae-bdda56a2ea27",
                    "EndpointID": "74eee15c87551b3a213e94c1f05e337d733fceddb78849eb1b59336fa62a831d",
                    "MacAddress": "00:15:5d:e6:0f:d1",
                    "IPv4Address": "172.20.140.160/16",
                    "IPv6Address": ""
                }
            },
            "Options": {
                "com.docker.network.windowsshim.hnsid": "3acfc61d-0d8e-438c-8857-9c2b742707bf",
                "com.docker.network.windowsshim.networkname": "nat"
            },
            "Labels": {}
        }
    ]

检查容器,缺少默认网关:

PS C:\Users\Administrator> docker inspect 4cd832e9b613
...
"Networks": {
    "nat": {
        "IPAMConfig": null,
        "Links": null,
        "Aliases": null,
        "NetworkID": "32ccb769f85ac73c317066dbe29f8c7cbf41b784c3dca6be9ac496285ae39d76",
        "EndpointID": "74eee15c87551b3a213e94c1f05e337d733fceddb78849eb1b59336fa62a831d",
        "Gateway": "",
        "IPAddress": "172.20.140.160",
        "IPPrefixLen": 16,
        "IPv6Gateway": "",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "MacAddress": "00:15:5d:e6:0f:d1"
    }
}

我尝试删除并重新创建 NAT 网络,但问题仍然存在。我通过以下命令执行了此操作:

Stop-Service -Name "docker"
Get-ContainerNetwork | Remove-ContainerNetwork
Created 'C:\ProgramData\Docker\config\daemon.json' with the following content:
{
    "bridge": "none"
}
Start-Service -Name "docker"
docker network create -d nat --subnet=192.168.1.0/24 --gateway=192.168.1.1 MyNatNetwork
docker run -itd --network "MyNatNetwork" --rm <image_name>

再次检查我的容器:

"Networks": {
    "MyNatNetwork": {
        "IPAMConfig": null,
        "Links": null,
        "Aliases": [
            "bdd983323dbd"
        ],
        "NetworkID": "8fc6b7710ebe0b48f2d7657449cb5f6a06c78ad5544e869c94d238c4e9e452e6",
        "EndpointID": "480dffc3cdb9058c1b3ca5b9091876a5b234592eba4d4ee851279381a5ad2790"
        "Gateway": "",
        "IPAddress": "192.168.1.121",
        "IPPrefixLen": 24,
        "IPv6Gateway": "",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "MacAddress": "00:15:5d:22:47:4a"
    }
}

相关内容