【问题标题】:How to launch docker container from mesos framework with port mappings?如何使用端口映射从 mesos 框架启动 docker 容器?
【发布时间】:2018-02-28 20:55:42
【问题描述】:

我想在自定义端口上使用 Mesos 框架启动 docker 容器,但不知道如何公开端口?我无法在桥接网络中启动 docker 容器。我向调度程序发送接受请求,如下所示:

{
   "framework_id":{"value":"FRAMEWORK_ID"},
   "type":"ACCEPT",
   "accept":{
      "offer_ids":[{"value":"SOME ID"}],
      "operations":[
         {
            "type":"LAUNCH",
            "launch":{
               "task_infos":[
                  {
                     "name":"My Task",
                     "task_id": {"value": "12220-3440-12532-my-task"},
                     "agent_id":{"value": "AGENT_ID"},
                     "command": {"shell": false},
                     "container":{
                        "type":"DOCKER",
                        "docker":{
                           "image":"someimage/chrome",
                           "network":"BRIDGE"
                        }
                     },
                     "resources":[
                        {
                           "name":"cpus",
                           "type":"SCALAR",
                           "scalar":{"value":1.0}
                        },
                        {
                           "name":"mem",
                           "type":"SCALAR",
                           "scalar":{"value":128.0}
                        }
                     ]
                  }
               ]
            }
         }
      ],
      "filters":{"refuse_seconds":5.0}
   }
}

我不能使用 Marathon,所以这样的东西不起作用:

"portMappings": [
      {
        "containerPort": 8080,
        "hostPort": 0,
        "servicePort": 11044,
        "protocol": "tcp",
        "labels": {}
      }
    ]

这个问题有解决办法吗?

【问题讨论】:

    标签: docker mesos


    【解决方案1】:

    您需要在container 字段中声明端口映射。

         "container":{
                        "type":"DOCKER",
                        "docker":{
                           "image":"someimage/chrome",
                           "network":"BRIDGE"
                        }
                        "port_mappings": [
                             {
                               "host_port": <port from offer>,
                               "container_port": 8080,
                               "protocol": "tcp"
                             }
                        ]
                     },
    

    参见 protobuf 方案:https://github.com/apache/mesos/blob/1.5.0/include/mesos/mesos.proto#L3122-L3129

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-28
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 2016-09-20
      • 2020-07-23
      • 2020-02-29
      相关资源
      最近更新 更多