Skip to main content

Posts

Showing posts with the label Redis

Docker Networking Fix: Connecting Redis Session Stores from Localhost

  You have just containerized a working backend application. It runs perfectly on your local machine using   npm run dev   or   go run main.go . However, the moment you spin it up inside a Docker container, your logs explode with a fatal error: Error: connect ECONNREFUSED 127.0.0.1:6379 You are attempting to connect to a Redis session store. You know Redis is running. You can connect to it via your CLI. Yet, the containerized application acts as if the database doesn't exist. This is the single most common networking hurdle developers face when migrating from bare-metal development to containerized environments. It stems from a fundamental misunderstanding of how Docker handles the loopback interface ( localhost ). The Root Cause: The Loopback Lie To fix this, you must understand why  127.0.0.1  fails inside a container. When your application runs directly on your host OS (Windows, macOS, or Linux),  localhost  refers to your computer's network in...