Docker – Mesos slave IP for Marathon-launched ( docker container ) service instance

apache-mesoscassandradockernetworking

i have a docker image i would like to launch a couple instances of via Mesos/Marathon.

i'm using BRIDGE networking in docker, and i would like to pass in the "public" ( i.e. not the container's docker0 net ) address of the mesos slave / docker host the container is being started on, to the starting container, via env var or param, so i can advertise this ip in application responses ( the application is a Cassandra node, and i will populate broadcast_address in cassandra.yaml with this address )

My understanding is that i can have Mesos forward any particular port ( within a configured range ) on this address back to the docker0 address of my running container. If this is true, and i can assure that the application instance ( Cassandra node ) does not get moved off this slave, with a couple constraints, i can have a mesos-scheduled Cassandra cluster.

My question is : how do i get the slave(docker host) ip address in to the Marathon application instance as it is being launched?

Best Answer

You don't know the IP address before Marathon finds suitable host for the task. However, at the time of launching a task at Mesos slave some properties are stored in ENV variables:

...
ULIMIT=-n 8192
HOST=slave01.example.com
MESOS_SLAVE_PID=slave(1)@192.168.1.2:5051
MARATHON_APP_RESOURCE_CPUS=0.1
MESOS_TASK_ID=dummy.eb6e1d9a-c2f0-11e5-a58b-00259057db2f

If you're fine with hostname, you can use HOST variable or extract the IP address from MESOS_SLAVE_PID.

If you start mesos-slave with --ip=192.168.1.2, then both HOST and LIBPROCESS_IP ENV variable will be set to host's address. For Mesosphere package:

echo "192.168.1.2" > /etc/mesos-slave/ip

and restart slave.

Yet another option is to resolve agent's IP inside Docker container:

AGENT_IP=$(getent hosts ${HOST} | awk '{ print $1 }')