【问题标题】:Why containerPort and hostPort need to be same in DCOS?为什么在 DCOS 中 containerPort 和 hostPort 需要相同?
【发布时间】:2018-08-29 20:09:44
【问题描述】:

我有一个 Web 应用程序,它具有以下应用程序定义和 DCOS 设置,并在部署了 marathon-lb 的 Azure 云上运行。当我将以下添加为服务时。

{
  "id": "web",
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "myimage",
      "network": "BRIDGE",
      "portMappings": [
        { "hostPort": 5000, "containerPort": 5000, "servicePort": 0 }
      ],
      "forcePullImage":true
    }
  },
  "instances": 1,
  "cpus": 0.1,
  "mem": 614,
  "labels":{
    "HAPROXY_GROUP":"external",
    "HAPROXY_0_VHOST":"localhost",
    "HAPROXY_0_MODE":"http"
  }
}

只有当我保持 containerPort 和 hostPort 相同时,我才能通过浏览器访问我的应用程序。

如果我将 hostPort 更改为 0 ,我将无法访问该应用程序。 而且我需要将 hostPort 设为 0,以便我可以扩展应用程序并将免费的 hostPort 分配给应用程序。 请问这里有什么问题吗?

【问题讨论】:

    标签: azure microservices mesos marathon dcos


    【解决方案1】:

    hostPort 等于 0 意味着您的应用程序将盯着 Mesos 分配的随机端口。见this answer

    您不需要保持hostPortcontainerPort 相等。 containerPort 必须与应用程序正在侦听的端口匹配。 hostPort 可能是任何端口(这就是您应该使用 0 的原因)。然后,Containerizer 会将发送到/从您的 hostPost 发送到/从您的 containertPort 发送到容器内的数据包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-17
      • 1970-01-01
      • 2020-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多