1

When I fire Windows containers in my dev box I get an IP address (via docker inspect) which can be use to connect to the container either from the host or from containers inside the compose (docker compose).

Unfortunately, I cannot get the same for Linux (regular) containers. When I use a similar compose file with Linux images I connect to them (from the host) via the loopback address which is not what I want. Can I get the same behavior I get with Windows containers without explicitly setting the IP address myself, exactly how is done with Windows containers?

sebagomez
  • 9,501
  • 7
  • 51
  • 89
  • "similar compose" how similar? Maybe you use a different networking mode? For example host mode will behave differently to default. – dbalakirev Aug 07 '17 at 13:20
  • imagine the same `docker-compose.yml` but different images, that is basically the only difference they have, I do not set a network or anything... maybe the default is different and that's why the behave that way... did I make myself clear? – sebagomez Aug 07 '17 at 15:06
  • can you spell it out for me? are you not able to connect with the docker containers using the ip returned from the docker inspect? – user3012759 Aug 07 '17 at 15:34
  • That's exactly what it is. I cannot connect to them using that IP address, I do can connect via localhost and the forwarded port. My web container forwards 80 to 5555 so I can reach that container thru `localhost:5555`. While the IP address returned by that container is 172.18.0.2 and I can't connect to either 172.18.0.2 or 172.18.0.2:5555 – sebagomez Aug 07 '17 at 16:42

2 Answers2

1

From: How to get a Docker container's IP address from the host?

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
KarateKid
  • 3,138
  • 4
  • 20
  • 39
  • I know how to get the IP, that's what I said I was doing for Windows Containers... that IP address does not behave the same way when talking with Linux containers – sebagomez Aug 07 '17 at 15:05
  • You can only connect to a port if its "exposed". See this for more details: https://stackoverflow.com/questions/22111060/difference-between-expose-and-publish-in-docker#22150099 – KarateKid Aug 08 '17 at 09:57
  • this is not what I mean, you're not understanding the question or comments – sebagomez Aug 08 '17 at 16:00
  • Well, I am not sure about Mac, but in Linux I have used this behavior thousands to time. The service (lets say nginx on port 443) is running in the container and in Dockerfile I "*expose*" the 443 port explicitly. After that its there is no problem with accessing the service directly via the ip addr of container and port(eg. 172.17.0.2:443). – KarateKid Aug 09 '17 at 11:15
1

Ok, so, to answer my own question, what I want is not posible, at least as of today. Somebody wrote a nice article on why I can't achieve what I want. Having said that, it is doable in Windows Containers, but it might be a temporary "limitation".

Link to the post: https://derickbailey.com/2016/08/29/so-youre-saying-docker-isnt-a-virtual-machine/ and link to the Docker Forum: https://forums.docker.com/t/access-dockerized-services-via-the-containers-ip-address/21151

sebagomez
  • 9,501
  • 7
  • 51
  • 89