Issue with ports in the docker container

I am trying to run a simple client-server program with client and server each in different containers.

On running the server container it gives a port and IP(always localhost i.e

When i try to provide the same port and IP while running the client container the socket connection fails.

I have tried following

  • Running individual programs - It works
  • On server in a container and client in shell - It doesn’t work
  • Both on the container - It doesn’t work.


I’m a little unsure of some of the details of your setup, but I’ll point out some general advice for this sort of thing.

  • isn’t a localhost address. It is an alias that basically says “all addresses on this host”.
  • Each container gets its own If I fire up a server on on my computer, then I can’t expect my friend’s computer to get to it by going to The same thing applies to containers, One container listening on would mean that only itself can connect to that service. Another container wouldn’t be able to get to it at all.
  • If you see in the output of docker ps, that is referring to all addresses on the docker host.
  • If a process inside a container is listening on and not its eth0 ip address, then port publishing at the docker level won’t be able to get to it. The port publishing works over the docker0 bridge, which is what the container’s eth0 is attached to.