Docker Community Forums

Share and learn in the Docker community.

Linking container networks

docker

(Colonelmo) #1

Is it possible to link two containers in such way that one could access some exposed port of the other one through localhost?

Say container A serves web on :80 and another container serves some other service on :8000. Can I link the two in a way that the first one could access the exposed port of the second one through “localhost:8000”?


(David Maze) #2

Not really. The best way to set this up is to make a private Docker network, and configure the client container to use the server container’s name as a hostname.

(Is it possible to link two physical servers so that one could refer to services on the other as “localhost”? Not really. You could, with enough iptables or ssh port forwarding magic, but it’s strange to do it; it’d be much more normal just to configure the client process to point to the DNS name of the server host.)