deimos icon indicating copy to clipboard operation
deimos copied to clipboard

Question: How does port pairing work?

Open tnolet opened this issue 10 years ago • 1 comments

Was looking around how to map multiple exposed ports to marathon/mesos ports using deimos. I was surprised by the following:

Starting a container that exposes ports 8080 and 8081, I (naively) assigned two ports in my json file:

{
    "container": {
    "image": "docker:///tnolet/hello:1.0",
    "options" : ["-P"]
  },
  "id": "hello2",
  "instances": "1",
  "cpus": ".5",
  "mem": "512",
  "uris": [],
  "cmd": "",
  "ports" : [40195,40196]
}

However, this resulted in deimos picking and auto incrementing two ports, 31267 and 31268:

Jul 31 17:17:17 ec2-54-84-57-179 deimos[5707]: deimos.docker.run() Port pairings (Mesos, Docker) // [(31627, 8080), (31628, 8081)]
Jul 31 17:17:17 ec2-54-84-57-179 deimos[5707]: deimos.containerizer.docker.launch() call // docker run --sig-proxy --rm --cidfile /tmp/deimos/mesos/54f421fd-0935-4f34-8be9-33a17862024e/cid -w /tmp/mesos-sandbox -v /tmp/deimos/mesos/54f421fd-0935-4f34-8be9-33a17862024e/fs:/tmp/mesos-sandbox -P -p 31627:8080 -p 31628:8081 -c 512 -m 512m -e PORT=31627 -e PORT0=31627 -e PORTS=31627,31628 -e PORT1=31628 tnolet/hello:1.0

If I leave the "port" key out of my json file, deimos only maps the lowest numbered port. I love the auto incremented ports, but I'm not sure how this is triggered.

tnolet avatar Jul 31 '14 17:07 tnolet

These auto-incremented ports are actually provided by Mesos, at Marathon's request. Deimos just maps the ports it sees in the TaskInfo -- it doesn't have any port management logic. That is why the port pairings are listed as (Mesos, Docker).

Jul 31 17:17:17 ec2-54-84-57-179 deimos[5707]: deimos.docker.run() Port pairings (Mesos, Docker) // [(31627, 8080), (31628, 8081)]

The idea is to access the endpoints resource on Marathon and then construct a proxy configuration (using HAProxy, for example) to map between the ports allocated for the container and the "service ports" requested in the Marathon task JSON.

solidsnack avatar Jul 31 '14 23:07 solidsnack