I would like to be able to get a list of all containers running on the same docker network from within a docker container. As the built in docker DNS can give me the IP addresses if I have the hostnames, it seems like it should be able to just give me a list of hostnames (maybe DNS cannot do this, I don't know).
Other approaches that I've thought of for getting a list of containers:
- Bind mount the docker socket into the container and use
docker ps
. Not a great idea as far as security goes. - Use
--link
which I believe places entries in/etc/hosts
. I could then read them from there, but this sort of defeats the purpose as I would have to already know the host names when I launched the container.
I'm looking to avoid using an external service discovery mechanism, but I would appreciate all suggestions for how to get a list of containers.