如何从具有端口映射的mesos框架启动docker容器?

时间:2018-02-19 17:52:29

标签: docker mesos

我想在自定义端口上启动带有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": {}
      }
    ]

这个问题有解决方法吗?

1 个答案:

答案 0 :(得分:0)

您需要在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