Hey everyone! I've got a bit of a head-scratcher regarding Docker networking. I have two applications running inside separate Docker containers on the same machine. They need to share data through some endpoints, and I initially configured them to use "http://localhost:port". However, even though they're on the same Bridge network, they weren't able to access each other's endpoints. After some troubleshooting, I switched the config to "https://:port" and that worked perfectly. Can someone explain why using localhost didn't work in this case? Thanks in advance! Cheers.
1 Answer
The reason why using 'localhost' fails here is that in a containerized environment, 'localhost' refers to the container itself. Each application is isolated within its own container. If they're on the same Docker network, you should actually use the container names to refer to each other, since IP addresses can change.
That makes sense! I can access both applications through the browser using 'localhost', but they can't communicate with each other using that method. What’s the difference in that case?