docker 暴露端口 查看_Docker容器如何暴露端口

docker 中定义了几种方式用于暴露容器中的端口,现将其总结如下.

dockerfile 中可以使用EXPOSE

指令

,仅说明容器需要对外暴露的端口,没有实际的暴露出去

EXPOSE [/…]

启动容器的时候通过参数指定

# 暴露特定端口到主机的特定端口

docker run -p 80:80

# 暴露容器的所有端口(exposed 端口)到主机的随机端口

docker run -P

# 添加dockerfile中expose 的端口

docker run -expose

dockerfile EXPOSE 指令

TheEXPOSE

instruction informs Docker that the container listens on the specified network ports at runtime. You can specify whether the port listens on TCP or UDP, and the default is TCP if the protocol is not specified.

TheEXPOSE

instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the-p

flag on docker run to publish and map on

    原文作者:Bvasn
    原文地址: https://blog.csdn.net/weixin_33511258/article/details/114166523
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞