Exposing Docker Container Ports

落花浮王杯 提交于 2019-12-24 12:17:19

问题


I understand that to expose ports in a docker container, you can use the -p flag (e.g. -p 1-100:1-100). But is there a nice way to expose a large percentage of possible ports from the container to the host machine? For instance if I am running a router of sorts in a container that lives in a VM, and I would like to expose all ports in the container from 32768 upwards to 65535, is there a nice way to do this? As it stands I've tried using the -p flag and it complains about memory allocation errors.


回答1:


Nvm. I figured out my misunderstanding. -P is what I want, and I want to expose and not explicitly map ports.




回答2:


tl;dr

docker run --net=host ...

Docker offers different networking modes for containers. By default the networking mode is bridge which implies the need to expose ports.

If you run a container with networking mode host then you won't need to expose/forward ports as both the docker host and the container will share the very same network interface.

In the container, localhost will refer to the docker host. Any port opened in the container is in fact opened on the docker host network interface.



来源:https://stackoverflow.com/questions/30900926/exposing-docker-container-ports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!