mesosphere-backup / deimos

Mesos containerizer hooks for Docker
Apache License 2.0
249 stars 26 forks source link

How to map service port to the random port? #26

Closed MikeMichel closed 10 years ago

MikeMichel commented 10 years ago

Hi,

what is the right way to get the service port of my app mapped to the random port marathon gives my container?

I can expose my port with expose and -P commands additionally but i still get a random port with a useless mapping.

So instead of

8080/tcp, 0.0.0.0:31013->31013/tcp

i would like to get

0.0.0.0:31013->8080/tcp

solidsnack commented 10 years ago

The random port Marathon allocates is actually for use by HAProxy...it's a little hard to understand at first. Basically, there is a "Marathon port" and a "Mesos port". Deimos understands and works with the Mesos port. Deimos never sees the "Marathon port", which you are supposed to bridge to with HAProxy.

We're not really what to do with this one going forward. Note that the environment variables PORT0 (PORT1, &c) contain the Mesos ports, not the Marathon ports.

alexandernilsson commented 10 years ago

I did a small hack to deimos/docker.py to read out the --exposed option and use that for the inner port in deimos.py run().

Replace line 22 with this: https://gist.github.com/alexandernilsson/1e4ea85099196b2787ec

It obviously only works with a single port. Submitting it as a gist instead of PR because I honestly don't like the approach myself.

solidsnack commented 10 years ago

What does the Marathon task look like that uses the --expose option?

solidsnack commented 10 years ago

@MikeMichel It would be great to see an example of a container spec and a Marathon request, as well as the desired port mappings.

MikeMichel commented 10 years ago

Seems i need to dive more into the marathon/mesos port thing but in the end i got what i needed by using app.listen(process.env.PORT) in the nodejs app i tried to deploy and let marathon do all the portmapping. Now i have working links to the app in the task tab of the marathon webgui and the produced haproxy output works too

listen fibu_15471
  bind 127.0.0.1:15471
  mode http
  option tcplog
  option httpchk GET /
  balance leastconn
  server fibu-3 MesosSlave01.fritz.box:31076 check
  server fibu-2 MesosSlave02:31564 check
  server fibu-1 MesosSlave01.fritz.box:31175 check

Right now i have no access to the environment for further testing. will continue in 2 weeks when im back from vacation.

Mike

ssorallen commented 10 years ago

It sounds like @solidsnack was able to help you solve this issue, so I'm going to close it. Feel free to comment again and reopen if you still have questions, @MikeMichel.