Docker Community Forums

Share and learn in the Docker community.

Get I.P Address of container running on worker node of a Swarm

I want to get the I.P of a container which is scaled up from a Docker Swarm. These container run on 2 worker nodes. I need to get the I.P address of one of the container. Currently what i do is, ssh into one of the worker node and do the following:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <Container-Name>

I get a chopped up result of the I.P’s of both containers that are part of the swarm. Is there a way to get just the I.P of one container?

Why do you want the IP of the container? Likely what you’d get is simply the internal bridge network IP, which won’t do you much good if you want to access it from the outside world

What i’m basically doing is building a Private DNS Container. In order to look up the domain name, I would need the I.P of the container. I plan to launch replicas of this container with the docker stack deploy . When an external app wants to query the domain name, i would need the container I.P

Hmm… if they will be running as part of a docker service in swarm mode you should get a DNS entry for service name automatically (within containers on the same network) which will load balance across the replicas using IPVS.

e.g., docker service create --network mynet --name myupstream ... will be accessible at myupstream by other services on the mynet network.

I think what cbingu is trying to do, though, is to make his docker container’s name resolvable for other machines on the network that the machines running the swarm are on, i.e. clients to a service running in the docker containers of the docker service. I believe what he really needs to do, rather than grab the IP of the container is to map the domain name he wants to use on the client network to the IP Address of one of the swarm machines (Or use a reverse proxy to get to them so if one node goes down the client gets routed to a running node). Then he just needs to expose the port for the service and by going to any IP at that port he should be good.

Or, maybe I’m wrong about the goal that cbingu has in mind.

Hey,

so just to clarify what i’m trying to do. Currently i have a DNS container built from compose. what i manually do is nslookup google.com . The Use case is that an app running remotely will query this DNS Container.

When i try to scale this up with docker-compose ‘3’ with docker stack deploy -c BIND, it brings up multiple DNS containers but the problem is querying this swarm. If the Swarm itself has an I.P or Hostname that i can query against, that would be ideal but i’m not sure how to set up something like that.

Ah, I see. So you’d like to be able to do something like dig @mycontainer
google.com ?

exactly. That would be ideal for me.

Why not --publish a port and then use dig -p on the port (and/or just publish on 53)?

I’m doing this currently but i’m also blocking www.yahoo.com in my named.conf . When i run dig -p 53 www.yahoo.com i get the I.P resolved instead of a NXDOMAIN. I’m guessing this is because its using my server’s DNS instead of the container’s?

when i use with container’s I.P dig @www.yahoo.com it works.