docker-compose端口与暴露端口有什么区别 [英] What is the difference between docker-compose ports vs expose

查看:251
本文介绍了docker-compose端口与暴露端口有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

docker-compose.yml中的端口 expose 选项之间有什么区别

What is the difference between ports and expose options in docker-compose.yml

推荐答案

根据 docker-compose reference


暴露端口。要么指定两个端口(HOST:CONTAINER),要么仅指定容器端口(将选择一个随机主机端口)。

Expose ports. Either specify both ports (HOST:CONTAINER), or just the container port (a random host port will be chosen).



    $ b docker-compose.yml中提到的$ b
  • 端口将在docker-compose启动的不同服务之间共享。

  • 端口将暴露给主机的随机端口或

  • 我的 docker-compose.yml 如下:

    mysql:
      image: mysql:5.7
      ports:
        - "3306"
    

    如果我这样做 docker-compose ps ,它将看起来像这样:

    If I do docker-compose ps, it will look like:

      Name                     Command               State            Ports
    -------------------------------------------------------------------------------------
      mysql_1       docker-entrypoint.sh mysqld      Up      0.0.0.0:32769->3306/tcp
    



    公开的定义为:



    Expose is defined as:


    公开端口而不将其发布到主机上-它们只能被访问链接服务。只能指定内部端口。

    Expose ports without publishing them to the host machine - they’ll only be accessible to linked services. Only the internal port can be specified.

    端口不暴露给主机,只暴露给其他服务。

    Ports are not exposed to host machines, only exposed to other services.

    mysql:
      image: mysql:5.7
      expose:
        - "3306"
    

    如果我这样做 docker-compose ps ,它将如下所示:

    If I do docker-compose ps, it will look like:

      Name                  Command             State    Ports
    ---------------------------------------------------------------
     mysql_1      docker-entrypoint.sh mysqld   Up      3306/tcp
    

    这篇关于docker-compose端口与暴露端口有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆