Docker Community Forums

Share and learn in the Docker community.

Issue with ports in the docker container


(Prashantabkari) #1

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 0.0.0.0)

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.

(Jeff Anderson) #2

Hello,

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.

  • 0.0.0.0 isn’t a localhost address. It is an alias that basically says “all addresses on this host”.
  • Each container gets its own 127.0.0.1. If I fire up a server on 127.0.0.1 on my computer, then I can’t expect my friend’s computer to get to it by going to 127.0.0.1. The same thing applies to containers, One container listening on 127.0.0.1 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 0.0.0.0 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 127.0.0.1 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.