marathon icon indicating copy to clipboard operation
marathon copied to clipboard

Cannot start docker job with UDP ports

Open logikal opened this issue 12 years ago • 13 comments

I was trying to stand up a Consul instance, intending to take advantage of the DNS resolver capabilities for service discovery.

Here's the error I get when I attempt to start a docker container for Consul with port 53/udp mapped

curl -X POST -H "Content-Type: application/json" http://10.111.111.111:8080/v2/apps [email protected]
{"message":"Can not construct instance of int from String value '53/udp': not a valid Integer value\n at [Source: org.eclipse.jetty.server.HttpInput@23292da0; line: 1, column: 198]"}% 

It looks like Marathon/Mesos assume that ports will always be integers. I didn't find a way in the docs or via google to map a UDP port. Is there a way to do so?

The docker container I'm using can be found at https://registry.hub.docker.com/u/progrium/consul/. for reference, my Consul job definition:

{
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "progrium/consul"
    }
  },
  "id": "consul",
  "instances": 1,
  "cpus": 1,
  "disk": 1024,
  "mem": 1024,
  "uris": [],
  "ports":[
    "53/udp"
  ]
}

Note that port 53 is not the only UDP port I need to be able to map, I just cut it down to one example to make sure I wasn't mixing something else up.

logikal avatar Aug 25 '14 02:08 logikal

Hi there @logikal:

The Docker support in Mesos 0.20.0 uses host-only networking; there should be no need to designate the transport layer protocol.

You should set the requirePorts flag if your intention is to bind to a specific port on the host.

In order to acquire this port, it must be offered as a resource by Mesos. By default the Mesos slave does not offer ports in this range. You can modify port resources via the --resources option when starting up the mesos slave. See http://mesosphere.io/docs/deep-dive/mesos-slave for more info.

Finally, be aware that binding to low-numbered ports typically requires root access. To accomplish this the Mesos slave process should run as root in order to successfully setuid.

Putting it all together, we have:

Mesos slave running as root with the following options:

  • --containerizers=docker,mesos
  • --resources="ports(*):[31000-32000, 53-53]"

and app JSON with:

{
  "ports": [53],
  "requirePorts": true,
  "user": "root"
}

Please let us know if you run into any other roadblocks.

ConnorDoyle avatar Aug 25 '14 21:08 ConnorDoyle

I'm not sure that I understand how this "The Docker support in Mesos 0.20.0 uses host-only networking; there should be no need to designate the transport layer protocol." should lead to me being able to expose UDP ports. Also - it's fine if those ports are randomly assigned high ports (30000s seem to be normal, and that's OK), I just need to be able to expose them.

TL;DR: How do I replicate this Docker UDP port mapping in Marathon, when it seems to expect all ports to be integers? docker run -p 53/udp -d libmesos/ubuntu /bin/nc -l -k -u 53

Specifying '53' in my port list does a TCP -> TCP port mapping, and doesn't expose the UDP port that's listening in the container.

It's quite possible I'm missing something in this stack, thanks for the help and guidance @ConnorDoyle !

logikal avatar Aug 26 '14 03:08 logikal

Ports are just integers here. I'm not an expert on the supported networking modes in Docker, but Mesos uses the simplest one: --net=host. Based on the Docker docs that explain the options, this mode effectively turns off the Docker networking magic. As far as I can tell this means your program is free to open a socket in the way it sees fit.

ConnorDoyle avatar Aug 26 '14 09:08 ConnorDoyle

Any ways to map to a different port? In docker run you could specify -p 8080:80 whereas in marathon 0.7.0 I can only map 80 to 80.

fillorkill avatar Aug 30 '14 18:08 fillorkill

Mesos currently doesn't allow you to have custom port mapping and itn

tnachen avatar Aug 30 '14 20:08 tnachen

Is planned for mesos 0.20.1 release. Once it is in Mesos marathon will be updated accordingly

tnachen avatar Aug 30 '14 20:08 tnachen

thanks. Anyway around that? Right now I can't run two instances of nginx as they both map to 80 on the host. Had to change nginx.conf manually to make it work. Imaging you had to do this for 100 containers.

fillorkill avatar Sep 02 '14 17:09 fillorkill

@fillorkill Sorry currently if you have a hard port requirement then in Marathon you must launch the task in another host for now. 0.20.1 is planned to be released this week so very soon you should be unblocked!

tnachen avatar Sep 02 '14 18:09 tnachen

Thanks tnachen. Would container linking be available too?

fillorkill avatar Sep 03 '14 13:09 fillorkill

Container linking won't be since on mesos side we can't guarantee the container you want to link with is on the same host and/or will continue to be. We want to provide linking that works transparently and mostly will need to rely on future docker features.

tnachen avatar Sep 03 '14 15:09 tnachen

@fillorkill @logikal Tim and I have been doing some work in advance to get this out soon. The Marathon work is here on GitHub in the docker_bridge branch and the app definition will look something like this: bridged.json.

This will definitely be a priority as soon as it's available in 0.20.1. Meanwhile, we've just tagged an RC for Marathon 0.7.0 with packages to be published tomorrow.

ConnorDoyle avatar Sep 10 '14 06:09 ConnorDoyle

That's great news! Thanks for tackling these!

On Tuesday, September 9, 2014, Connor Doyle [email protected] wrote:

@fillorkill https://github.com/fillorkill @logikal https://github.com/logikal Tim and I have been doing some work in advance to get this out soon. The Marathon work is here on GitHub in the docker_bridge branch https://github.com/mesosphere/marathon/compare/docker_bridge and the app definition will look something like this: bridged.json https://gist.github.com/ConnorDoyle/b5a3fe1fa6d71679bb92.

This will definitely be a priority as soon as it's available in 0.20.1. Meanwhile, we've just tagged an RC for Marathon 0.7.0 with packages to be published tomorrow.

— Reply to this email directly or view it on GitHub https://github.com/mesosphere/marathon/issues/478#issuecomment-55075423.

logikal avatar Sep 10 '14 06:09 logikal

Fixed by #621

ConnorDoyle avatar Sep 30 '14 07:09 ConnorDoyle