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:
If you're fine with hostname, you can use
HOST
variable or extract the IP address fromMESOS_SLAVE_PID
.If you start
mesos-slave
with--ip=192.168.1.2
, then bothHOST
andLIBPROCESS_IP
ENV variable will be set to host's address. For Mesosphere package:and restart slave.
Yet another option is to resolve agent's IP inside Docker container: