无法从 Windows 访问 Docker 容器 Web 地址(172.17.0.2)

发布于 2025-01-11 09:39:57 字数 629 浏览 0 评论 0原文

我正在使用 docker 桌面,我已将 prometheus 作为容器运行:

在此处输入图像描述

命令 docker 检查显示该容器正在网关 172.17.0.2 端口上运行9090.

“网络”:{ “桥”: { “IPAMConfig”:空, “链接”:空, “别名”:空, “网络ID”:“a112bcf4dbabbfdb5b3e14c9d286469a482557c78d42854a5ae3e754ca44fd5d”, “端点ID”:“0ecc79513b555daebb51947a6a6a73bb26f0974542a6f79d14013b8b1572a589”, “网关”:“172.17.0.1”, "IP地址": "172.17.0.2", “IP前缀长度”:16, "IPv6网关": "", "全球IPv6地址": "", "全局IPv6前缀长度": 0, "Mac地址": "02:42:ac:11:00:02", “驱动程序选项”:空 } 但是

当这个地址在我的浏览器中无法访问时。

有人可以帮忙吗

i'm using docker desktop , I have runned prometheus as a container :

enter image description here

the commande docker inspect is showing that this container is running on the gateway 172.17.0.2 on port 9090 .

"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "a112bcf4dbabbfdb5b3e14c9d286469a482557c78d42854a5ae3e754ca44fd5d",
"EndpointID": "0ecc79513b555daebb51947a6a6a73bb26f0974542a6f79d14013b8b1572a589",
"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
}
}

but when this address is not rechable in my browser .

could any one please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸印温柔 2025-01-18 09:39:57

没错:您无法访问 Windows 主机上的 docker inform IP 地址。如果您的 Docker 更明确地位于虚拟机内(使用 Docker Toolbox 或适用于您的 Docker 环境的 Minikube 等工具),或者您从容器中的不同主机进行调用,您也无法从 MacOS 主机访问它。该 IP 地址几乎没有任何用处,您根本不需要查找它。

启动容器时,您可以选择 从中发布端口。如果 Prometheus 通常侦听端口 9000,则可能看起来像

docker run \
  -d \                # in the background
  --name prometheus \ # with a name so it's easier to manage
  -p 9123:9000 \      # host port 9123 -> container port 9000
  bitnami/prometheus

第二个端口号必须与图像所期望的完全匹配。第一个端口号可以是任何未使用的端口号。这些端口通常相同,但并非必须如此。

一旦有了这个 docker run -p 选项,您就可以使用第一个端口号来访问容器; http://localhost:9123 如果您位于同一主机上(并且没有使用 Docker Toolbox 或类似的基于虚拟机的设置)。

如果您没有此选项,请 docker stopdocker rm 现有容器,以及 docker run 一个具有正确设置的新容器。这是非常常规的,与使用 Ctrl+C 停止命令行进程然后使用不同的命令行参数运行它非常相似。

That's correct: you can't access the docker inspect IP address on a Windows host. You also can't access it from a MacOS host, if your Docker is more explicitly inside a virtual machine (using Docker Toolbox or a tool like Minikube for your Docker environment), or if you're calling from a different host from the container. This IP address is almost never useful and you shouldn't need to look it up at all.

When you start a container, you have the option to publish ports from it. If Prometheus normally listens on port 9000, this could look like

docker run \
  -d \                # in the background
  --name prometheus \ # with a name so it's easier to manage
  -p 9123:9000 \      # host port 9123 -> container port 9000
  bitnami/prometheus

The second port number must exactly match what the image is expecting. The first port number can be anything that's not otherwise in use. The ports are frequently the same but don't have to be.

Once you have this docker run -p option, you can use the first port number to access the container; http://localhost:9123 if you're on the same host (and aren't using Docker Toolbox or a similar VM-based setup).

If you don't have this option, docker stop and docker rm the existing container and docker run a new one with the right settings. This is extremely routine, very similar to using Ctrl+C to stop a command-line process and then run it with different command-line arguments.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文