Windows Docker容器无法访问局域网
我使用docker 17.06.0-ce运行Windows Server 2016,并且有两个容器,在同一个网络上还有另一台服务器,它承载着一个HTTP服务器。
容器1是从microsoft/dotnet-framework:4.6.2
图像microsoft/dotnet-framework:4.6.2
并且可以成功与HTTP服务器进行通信
容器2是从microsoft/dotnet:1.1.2-runtime-nanoserver
映像microsoft/dotnet:1.1.2-runtime-nanoserver
, 无法与HTTP服务器通信
两个包含在同一个docker网络中,这是Docker创建的默认nat网络
除了基本映像之外,唯一真正的区别是容器1在tcp端口上侦听,而容器2不在。
这是docker inspect
的输出
容器1
[ { "Id": "404d68744106bc72badf1fd3faa36740ef37c74fae5bf8776b398cde4352930b", "Created": "2017-07-25T08:17:00.6037441Z", "Path": "setup.bat", "Args": [ "MyService.exe" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 1104, "ExitCode": 0, "Error": "", "StartedAt": "2017-07-25T08:17:07.3661604Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:7635d68b41d16be7ab21a0861905fdc383533dc9d74bafa03aa8b03c3eb15cda", "ResolvConfPath": "", "HostnamePath": "", "HostsPath": "", "LogPath": "C:\\ProgramData\\docker\\containers\\404d68744106bc72badf1fd3faa36740ef37c74fae5bf8776b398cde4352930b\\404d68744106bc72badf1fd3faa36740ef37c74fae5bf8776b398cde4352930b-json.log", "Name": "/container1", "RestartCount": 0, "Driver": "windowsfilter", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": { "8080/tcp": [ { "HostIp": "", "HostPort": "8080" } ] }, "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "Dns": null, "DnsOptions": null, "DnsSearch": null, "ExtraHosts": [ "machine1:10.0.2.192" ], "GroupAdd": null, "IpcMode": "", "Cgroup": "", "Links": null, "OomScoreAdj": 0, "PidMode": "", "Privileged": false, "PublishAllPorts": false, "ReadonlyRootfs": false, "SecurityOpt": null, "UTSMode": "", "UsernsMode": "", "ShmSize": 0, "ConsoleSize": [ 0, 0 ], "Isolation": "process", "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, "DiskQuota": 0, "KernelMemory": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": null, "OomKillDisable": null, "PidsLimit": 0, "Ulimits": null, "CpuCount": 0, "CpuPercent": 0, "IOMaximumIOps": 0, "IOMaximumBandwidth": 0 }, "GraphDriver": { "Data": { "dir": "C:\\ProgramData\\docker\\windowsfilter\\404d68744106bc72badf1fd3faa36740ef37c74fae5bf8776b398cde4352930b" }, "Name": "windowsfilter" }, "Mounts": [], "Config": { "Hostname": "404d68744106", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "8080/tcp": {}, "8081/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ ], "Cmd": [ "setup.bat", "MyService.exe" ], "ArgsEscaped": true, "Image": "***************", "Volumes": null, "WorkingDir": "C:\\app", "Entrypoint": null, "OnBuild": null, "Labels": { } }, "NetworkSettings": { "Bridge": "", "SandboxID": "787a0af6cd7bfbac8910775f32ccaf1777087d23c0d29fa353467f2d2802023e", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": { "8080/tcp": [ { "HostIp": "0.0.0.0", "HostPort": "8080" } ], "8081/tcp": null }, "SandboxKey": "787a0af6cd7b", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "MacAddress": "", "Networks": { "nat": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "c67370bf94d3c1824b128e48d7a007266cc9b20f3af834ea323e074af774c929", "EndpointID": "a8fbaca93337c1cd40260d0ef7c9f5fad5b07e041a579df2c909031f2f9818dc", "Gateway": "172.20.0.1", "IPAddress": "172.20.9.163", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "00:15:5d:4f:59:35", "DriverOpts": null } } } } ]
容器2
[ { "Id": "fc0632ecb5d64d2a11662843434df31222ba21111d45206ecbfb1efb05f2cd3c", "Created": "2017-07-25T07:57:22.306452Z", "Path": "setup.bat", "Args": [ "dotnet", "MyService.dll", "config.conf" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 6288, "ExitCode": 0, "Error": "", "StartedAt": "2017-07-25T07:57:26.788172Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:c104b07d2a09a5f8b2f3963cd4b8be6537ac8b482fe55d72aec6dfb98001fc5f", "ResolvConfPath": "", "HostnamePath": "", "HostsPath": "", "LogPath": "C:\\ProgramData\\docker\\containers\\fc0632ecb5d64d2a11662843434df31222ba21111d45206ecbfb1efb05f2cd3c\\fc0632ecb5d64d2a11662843434df31222ba21111d45206ecbfb1efb05f2cd3c-json.log", "Name": "/Container2", "RestartCount": 0, "Driver": "windowsfilter", "MountLabel": "", "ProcessLabel": "", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": null, "ContainerIDFile": "", "LogConfig": { "Type": "json-file", "Config": {} }, "NetworkMode": "default", "PortBindings": {}, "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, "AutoRemove": false, "VolumeDriver": "", "VolumesFrom": null, "CapAdd": null, "CapDrop": null, "Dns": null, "DnsOptions": null, "DnsSearch": null, "ExtraHosts": [ "machine1:10.0.2.192" ], "GroupAdd": null, "IpcMode": "", "Cgroup": "", "Links": null, "OomScoreAdj": 0, "PidMode": "", "Privileged": false, "PublishAllPorts": false, "ReadonlyRootfs": false, "SecurityOpt": null, "UTSMode": "", "UsernsMode": "", "ShmSize": 0, "ConsoleSize": [ 0, 0 ], "Isolation": "process", "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, "DiskQuota": 0, "KernelMemory": 0, "MemoryReservation": 0, "MemorySwap": 0, "MemorySwappiness": null, "OomKillDisable": null, "PidsLimit": 0, "Ulimits": null, "CpuCount": 0, "CpuPercent": 0, "IOMaximumIOps": 0, "IOMaximumBandwidth": 0 }, "GraphDriver": { "Data": { "dir": "C:\\ProgramData\\docker\\windowsfilter\\fc0632ecb5d64d2a11662843434df31222ba21111d45206ecbfb1efb05f2cd3c" }, "Name": "windowsfilter" }, "Mounts": [], "Config": { "Hostname": "container2", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ ], "Cmd": [ "setup.bat", "dotnet", "MyService.dll", "config.conf" ], "ArgsEscaped": true, "Image": "***************", "Volumes": null, "WorkingDir": "C:\\dotnetapp", "Entrypoint": null, "OnBuild": null, "Labels": { } }, "NetworkSettings": { "Bridge": "", "SandboxID": "66b8d49f77cf6d04080120f4cee6a5691158b679271c5607958528f60be76bde", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "66b8d49f77cf", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "MacAddress": "", "Networks": { "nat": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "c67370bf94d3c1824b128e48d7a007266cc9b20f3af834ea323e074af774c929", "EndpointID": "1216785620c6d28b499b1556a132e665274afd8470d77cc167e2b97a950cd120", "Gateway": "172.20.0.1", "IPAddress": "172.20.8.65", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "00:15:5d:4f:59:78", "DriverOpts": null } } } } ]