Skip to main content

Posts

Showing posts with the label Microservices

Docker Networking 101: Why 'localhost' Fails Between Containers

  It is the quintessential "it works on my machine" scenario. You build a modern full-stack application—perhaps a React frontend and a Node.js API. You run them locally in separate terminal tabs. The frontend communicates with   http://localhost:3000 , and everything works perfectly. Then, you decide to professionalize your workflow by wrapping the services in Docker containers. You spin them up, check the logs, and see the dreaded error: FetchError: request to http://127.0.0.1:3000/api failed, reason: connect ECONNREFUSED 127.0.0.1:3000 If you are encountering this, your code isn't broken, but your mental model of network topology needs a slight adjustment. This guide explains exactly why  localhost  betrays you inside Docker and provides the industry-standard architecture to fix it. The Root Cause: Network Namespaces To understand the solution, we must look under the hood of the Linux kernel. Docker containers are not just lightweight virtual machines; they are iso...