Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Possible to use ip addresses and DNS names for docker containers in OS X bridge network #3402
I would like to be able to connect to my docker containers by their host name from my host OS X laptop. I do not know if this is supported, or what network configuration options would need to be enabled.
I installed docker using the Docker Toolbox (https://docs.docker.com/mac/step_one/)
I am trying to deploy the following compose file
After deploying that compose file, I would like to be able to access the two docker images by the hostnames (amb-server.docker_cloud and amb-agent-1.docker_cloud) from my host laptop rmelick-macbook. When I try to ping, I see this error:
If I log into one of the docker containers, everything works fine
If I use this ip address from my host laptop, it also fails
If I log on to the docker-machine (default), the dns lookup fails, but the ping by ip address functions correctly
Is there any way to expose the dns and ip addresses of this bridge network to my host laptop? The documentation (https://docs.docker.com/engine/userguide/networking/dockernetworks/#a-bridge-network) seems to say that I can only expose specific ports when using a bridge network.
The real reason I want to do this is we're attempting to deploy hadoop within docker, and the internal hadoop services are all configured with the hostnames of the different docker containers. I would like to be able to run code outside of a docker container that can connect with Hadoop running inside docker. If this doesn't work, it seems I will have to run all of my code inside docker containers that join that network.
Does anyone have a solution for this problem? I am trying to doing something similar: running a Kafka broker instance (one-node cluster) in a container and connecting to it from the host (mac-os). The kafka client lib connects to the broker itself by localhost:exported-port fine, but then queries it for the "list of node addresses", which are of form "containername:port" which it then cannot resolve in the host environment.
I wish to be able to execute automated integration tests against this kafka broker; I have tests that work fine for other software in docker containers, but cannot get Kafka tests working because of this "get list of node addresses" operation which returns addresses that the caller cannot resolve.
My solution is documented here: http://moi.vonos.net/java/network-name-mapper/
In summary, I use Java reflection to override java.net.INetAddress.getAddress() and map the docker container name to the appropriate IP address. It is somewhat of a hack, but does the job..
@tgudlek Using localhost works when the cluster is a single node and the only thing that talks to the Kafka broker is the app outside the container environment. If you have another container which also talks to Kafka (eg a kafka-connector instance, or a schema-registry) then using "localhost" as the advertised address for the broker node no longer works for obvious reasons.