如何使用Docker暴露多个端口?
So I have 3 ports that should be exposed to the machine's interface. 所以我有3个端口应该暴露在机器的界面上。 Is it pos
本文翻译自:How can I expose more than 1 port with Docker?
So I have 3 ports that should be exposed to the machine's interface. 所以我有3个端口应该暴露在机器的界面上。 Is it possible to do this with a Docker container? 是否可以使用Docker容器执行此操作?
#1楼
参考:https://stackoom.com/question/1PSka/如何使用Docker暴露多个端口
#2楼
To expose just one port, this is what you need to do: 要暴露一个端口,这是您需要做的:
docker run -p <host_port>:<container_port>
To expose multiple ports, simply provide multiple -p
arguments: 要公开多个端口,只需提供多个-p
参数:
docker run -p <host_port1>:<container_port1> -p <host_port2>:<container_port2>
#3楼
Step1 步骤1
In your Dockerfile
, you can use the verb EXPOSE
to expose multiple ports. 在Dockerfile
,您可以使用动词EXPOSE
来显示多个端口。
eg 例如
EXPOSE 3000 80 443 22
Step2 第2步
You then would like to build an new image based on above Dockerfile
. 然后,您想基于上面的Dockerfile
构建一个新图像。
eg 例如
docker build -t foo:tag .
Step3 第三步:
Then you can use the -p
to map host port with the container port, as defined in above EXPOSE
of Dockerfile
. 然后可以使用-p
映射主机端口与所述容器端口,如在上面所定义EXPOSE
的Dockerfile
。
eg 例如
docker run -p 3001:3000 -p 23:22
In case you would like to expose a range of continuous ports, you can run docker like this: 如果您想公开一系列连续端口,可以像这样运行docker:
docker run -it -p 7100-7120:7100-7120/tcp
#4楼
if you use docker-compose.yml
file: 如果你使用docker-compose.yml
文件:
services:
varnish:
ports:
- 80
- 6081
You can also specify the host/network port 您还可以指定主机/网络端口
varnish:
ports:
- 80:80
- 6081:6081
更多推荐
所有评论(0)