gpt4 book ai didi

docker - 使 docker 机器在 Windows 中的主机名下可用

转载 作者:IT老高 更新时间:2023-10-28 21:19:37 25 4
gpt4 key购买 nike

我正在尝试通过主机名使 docker 机器对我的 Windows 可用。创建后就像

docker-machine create -d virtualbox mymachine

并设置一个暴露端口 80 的 docker 容器,我怎样才能给该 docker 机器一个主机名,以便我可以在浏览器中输入“http://mymachine/”来加载网站?当我将“mymachine”更改为实际的 IP 地址时,它就可以工作了。

有一个 answer对此question但我想在 hosts 文件中没有条目的情况下实现它。这可能吗?

最佳答案

您可能需要引用 docker 文档: https://docs.docker.com/engine/userguide/networking/#exposing-and-publishing-ports

You expose ports using the EXPOSE keyword in the Dockerfile or the --expose flag to docker run. Exposing ports is a way of documenting which ports are used, but does not actually map or open any ports. Exposing ports is optional.

You publish ports using the --publish or --publish-all flag to docker run. This tells Docker which ports to open on the container’s network interface. When a port is published, it is mapped to an available high-order port (higher than 30000) on the host machine, unless you specify the port to map to on the host machine at runtime. You cannot specify the port to map to on the host machine when you build the image (in the Dockerfile), because there is no way to guarantee that the port will be available on the host machine where you run the image.

我还建议查看 -P 标志,因为它与 -p 标志不同。

另外我建议你尝试 Windows 或 Mac 的“Kitematic”,https://kitematic.com/ .它更简单(但不要忘记在任何更改后提交!)

现在关于您公司的网络,它与docker无关,只要您在计算机上本地使用docker,您公司设置的配置无关紧要。即使您不必更改任何 VM 网络配置即可将内容公开给本地主机,如果您使用 Vbox(适配器 1 ==> NAT 和适配器 2 ==> 仅限主机),则默认情况下所有这些配置都会出现

希望这就是你要找的东西

关于docker - 使 docker 机器在 Windows 中的主机名下可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47514815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com