如何通过默认IP在本地主机上运行docker容器? [英] How can I run a docker container on localhost over the default IP?

查看:251
本文介绍了如何通过默认IP在本地主机上运行docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注

同时,当我出于某种原因运行它时,它在IP 10.0.75.2上运行:

Meanwhile, when I run it it for some reason it runs on the IP 10.0.75.2:

有没有发生这种情况的特殊原因?并可以像示例中一样使它在localhost上运行吗?

Is there any particular reason why this is happening? And is there any way to get it to run on localhost like in the example?

编辑 >:我尝试使用-net = host ,但没有结果:

Edit: I tried using --net=host but had no results:

推荐答案

默认网络已桥接。 0.0.0.0:49166->443 显示了由于-而将容器中暴露的端口映射到主机上的高级端口的端口映射P 选项。您可以通过将标志更改为 -p 8080:80 -p 443:443 来手动映射特定端口,以将主机上的端口8080和443映射到容器中。

The default network is bridged. The 0.0.0.0:49166->443 shows a port mapping of exposed ports in the container to high level ports on your host because of the -P option. You can manually map specific ports by changing that flag to something like -p 8080:80 -p 443:443 to have port 8080 and 443 on your host map into the container.

您也可以根据需要将默认网络更改为主机网络。这消除了容器提供的某些隔离和保护,并限制了您在容器之间配置集成的能力,这就是为什么它不是默认选项。该语法为:

You can also change the default network to be your host network as you've requested. This removes some of the isolation and protections provided by the container, and limits your ability to configure integrations between containers, which is why it is not the default option. That syntax would be:

docker run --name nginx1 --net=host -d nginx






编辑:从您的评论和重新阅读中,我看到您也在询问哪里IP地址10.0.75.2来自。这基于您启动docker守护程序的方式。当您将-ip 标志传递给守护程序此处的文档。如果您要在具有docker-machine的虚拟机中运行docker,我希望这是您的虚拟机的IP。


from your comments and a reread I see you're also asking about where the 10.0.75.2 ip address comes from. This is based on how you launch the docker daemon. That IP binding is assigned when you pass the --ip flag to the daemon documentation here. If you're running docker in a vm with docker-machine, I'd expect this to be the IP of your vm.

这篇关于如何通过默认IP在本地主机上运行docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆