Exposing Docker Container Ports

2019-08-11 06:36发布

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.

2条回答
一纸荒年 Trace。
2楼-- · 2019-08-11 07:13

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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-08-11 07:22

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

查看更多
登录 后发表回答