Windows Docker 容器没有 NAT IP 地址。无法在本地访问容器
Windows Docker Container has no NAT IP Address. Cannot access container locally
首先要明确的是,我的 docker 容器的 IP 地址在 NetworkSettings.Networks.bridge
下。该 IP 是 172.17.0.2
但是我无法通过 http://172.17.0.2:3000/
在 运行 之后使用 docker run -p 3000:3000 node:8.10.0
访问容器
我的研究表明它在 windows 上与 docker 本地工作时很粗糙。按照这个简短的指南:https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/
我遇到过使用网络 NAT IP 地址的情况。我看到这个推荐了几个地方。但是我的 docker inspect
的那部分根本不存在。
它returns:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "0c81d8f7ce5bcba70ec0487bbfe91bc6f221e29d9378c33708fac78d0ae47d3e",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "3000"
}
]
},
"SandboxKey": "/var/run/docker/netns/0c81d8f7ce5b",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "bbe5f42a5b53c001bd3c2852bc6b22976fb9bab2afcb88b30f6660d7662f526f",
"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": "0af66a62bc57ce25491c82f5a13d947ca79f5a879f3c1a6db40a90233eeb04f8",
"EndpointID": "bbe5f42a5b53c001bd3c2852bc6b22976fb9bab2afcb88b30f6660d7662f526f",
"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
}
}
如您所见,NAT 部分完全缺失。我在网上找不到任何提到原因或如何解决的内容。我希望它丢失会是一件好事,并使其更容易连接。唉,事实并非如此。任何帮助表示赞赏。这是 docker 文件:
FROM node:8.10.0
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD ["./node_modules/gulp/bin/gulp.js", "assets"]
CMD [ "node", "app.js" ]
EXPOSE 3000
这是 docker windows 下的一个已知错误。它已在 19.03 中修复。因此,请尝试更新您的 docker 引擎。
首先要明确的是,我的 docker 容器的 IP 地址在 NetworkSettings.Networks.bridge
下。该 IP 是 172.17.0.2
但是我无法通过 http://172.17.0.2:3000/
在 运行 之后使用 docker run -p 3000:3000 node:8.10.0
我的研究表明它在 windows 上与 docker 本地工作时很粗糙。按照这个简短的指南:https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/
我遇到过使用网络 NAT IP 地址的情况。我看到这个推荐了几个地方。但是我的 docker inspect
的那部分根本不存在。
它returns:
"NetworkSettings": {
"Bridge": "",
"SandboxID": "0c81d8f7ce5bcba70ec0487bbfe91bc6f221e29d9378c33708fac78d0ae47d3e",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "3000"
}
]
},
"SandboxKey": "/var/run/docker/netns/0c81d8f7ce5b",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "bbe5f42a5b53c001bd3c2852bc6b22976fb9bab2afcb88b30f6660d7662f526f",
"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": "0af66a62bc57ce25491c82f5a13d947ca79f5a879f3c1a6db40a90233eeb04f8",
"EndpointID": "bbe5f42a5b53c001bd3c2852bc6b22976fb9bab2afcb88b30f6660d7662f526f",
"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
}
}
如您所见,NAT 部分完全缺失。我在网上找不到任何提到原因或如何解决的内容。我希望它丢失会是一件好事,并使其更容易连接。唉,事实并非如此。任何帮助表示赞赏。这是 docker 文件:
FROM node:8.10.0
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD ["./node_modules/gulp/bin/gulp.js", "assets"]
CMD [ "node", "app.js" ]
EXPOSE 3000
这是 docker windows 下的一个已知错误。它已在 19.03 中修复。因此,请尝试更新您的 docker 引擎。