Py学习  »  docker

docker run命令中小写“-p”和大写“-p”参数之间有什么区别?

Matt C. • 2 年前 • 472 次点击  

在运行docker容器时,我注意到您可以提供小写字母 -p 还是大写 -P 论点我知道 -p/-P 标记涉及从docker容器发布端口,使其可用于docker之外的服务,或未连接到容器网络的docker容器。然而,我似乎找不到一个关于小写字母之间区别的明确解释 -p 而且是首都 -P .

我在谷歌上搜索过,搜索过SO,搜索过Docker文档,但还没有找到这个问题的明确答案。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/131576
 
472 次点击  
文章 [ 2 ]  |  最新文章 2 年前
saeed
Reply   •   1 楼
saeed    2 年前

根据 Docker Run Docs :

-P         : Publish all exposed ports to the host interfaces
-p=[]      : Publish a container's port or a range of ports to the host
               format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
               Both hostPort and containerPort can be specified as a
               range of ports. When specifying ranges for both, the
               number of container ports in the range must match the
               number of host ports in the range, for example:
                   -p 1234-1236:1234-1236/tcp
shree.pat18
Reply   •   2 楼
shree.pat18    2 年前

documentation :

P选项将所有端口发布到主机接口。Docker将每个公开的端口绑定到主机上的一个随机端口。端口范围在/proc/sys/net/ipv4/ip_local_port_range定义的临时端口范围内。

使用-p标志显式映射单个端口或端口范围。