0

Getting started with Docker I do not understand why two containers on the same docker machine can't communicate through localhost.

I read about this SO post already : how-to-connect-two-docker-containers-through-localhost but could not get a clear answer.

My use case, I am on Windows Home using Docker Toolbox (virtualbox) having the current docker machine :

NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376           v19.03.5

I am launching 3 services, one react application, one spring boot application, and one postgreSQL database.

In my understanding each one will be hosted on 192.168.99.100 on the port I specified (respectively 3000, 8080, 5432). So each one in their context should have localhost refering to 192.168.99.100.

I know it is not working like that because of CORS issues that I only get when launching the app environment with docker.

Why is that ? Can someone explain ?

Logan Wlv
  • 3,274
  • 5
  • 32
  • 54
  • Each _container_ has its own network namespace and its own notion of `localhost`. (Which is synonymous with the magic IP address 127.0.0.1.) `localhost` usually means "this container" and not "this Docker VM" or "this physical host". Also note that the React application runs in the browser, not in Docker space, so `localhost` there refers to the machine the browser is running on. – David Maze Feb 23 '20 at 14:09
  • @DavidMaze thanks for the link it's indead a duplicate ! – Logan Wlv Feb 23 '20 at 14:16

0 Answers0