Claude Code integration

Docker Compose Services Fail to Connect Due to Wrong Names

Your Docker Compose setup generated by Claude Code has services that fail to connect to each other. The application container can't reach the database, the backend can't connect to Redis, or the worker can't find the message broker. Everything works when running services individually but fails in Docker Compose.

Docker Compose creates a network where services can reach each other by their service name. When the application code uses 'localhost' or hardcoded IPs instead of service names, or when service names in docker-compose.yml don't match what the application expects, connections fail.

This is especially frustrating because the error messages often just say 'connection refused' or 'host not found' without indicating that the issue is a name mismatch.

Error Messages You Might See

Error: connect ECONNREFUSED 127.0.0.1:5432 psql: could not connect to server: Connection refused redis.exceptions.ConnectionError: Error connecting to redis:6379 getaddrinfo ENOTFOUND database Name or service not known
Error: connect ECONNREFUSED 127.0.0.1:5432psql: could not connect to server: Connection refusedredis.exceptions.ConnectionError: Error connecting to redis:6379getaddrinfo ENOTFOUND databaseName or service not known

Common Causes

  • Using localhost instead of service name — Application code connects to localhost:5432 but the database is in a separate container reachable by its service name
  • Service name mismatch — docker-compose.yml defines the service as 'postgres' but the app config references 'db' or 'database'
  • Missing depends_on — The app container starts before the database is ready to accept connections
  • Wrong port mapping confusion — Using the host-mapped port (5433) instead of the container's internal port (5432)
  • Custom network not shared — Services in different docker-compose files or custom networks can't see each other

How to Fix It

  1. Replace localhost with service names — Change database URLs from localhost:5432 to postgres:5432 (matching the service name in docker-compose.yml)
  2. Use environment variables for hostnames — Define DB_HOST, REDIS_HOST as environment variables in docker-compose.yml pointing to the correct service names
  3. Add proper health checks — Use healthcheck in docker-compose.yml and depends_on with condition: service_healthy to wait for dependencies
  4. Use internal container ports — Between containers, always use the internal port (5432), not the host-mapped port (5433:5432)
  5. Verify with docker compose exec — Shell into a container and try to ping or connect to the service name to debug networking

Real developers can help you.

Jen Jacobsen Jen Jacobsen I’m a Full-Stack Developer with over 10 years of experience building modern web and mobile applications. I enjoy working across the full product lifecycle — turning ideas into real, well-built products that are intuitive for users and scalable for businesses. I particularly enjoy building mobile apps, modern web platforms, and solving complex technical problems in a way that keeps systems clean, reliable, and easy to maintain. Jared Hasson Jared Hasson Full time lead founding dev at a cyber security saas startup, with 10 yoe and a bachelor's in CS. Building & debugging software products is what I've spent my time on for forever Alvin Voo Alvin Voo I’ve watched the tech landscape evolve over the last decade—from the structured days of Java Server Pages to the current "wild west" of Agentic-driven development. While AI can "vibe" a frontend into existence, I specialize in the architecture that keeps it from collapsing. My expertise lies in the critical backend infrastructure: the parts that must be fast, secure, and scalable. I thrive on high-pressure environments, such as when I had only three weeks to architect and launch an Ethereum redemption system with minimal prior crypto knowledge, turning it into a major revenue stream. What I bring to your project: Forensic Debugging: I don't just "patch" bugs; I use tools like Datadog and Explain Analyzers to map out bottlenecks and resolve root causes—like significantly reducing memory usage by optimizing complex DB joins. Full-Stack Context: Deep experience in Node.js and React, ensuring backends play perfectly with mobile and web teams. Sanity in the Age of AI: I bridge the gap between "best practices" and modern speed, ensuring your project isn't just built fast, but built to last. rayush33 rayush33 JavaScript (React.js, React Native, Node.js) Developer with demonstrated industry experience of 4+ years, actively looking for opportunities to hone my skills as well as help small-scale business owners with solutions to technical problems zipking zipking I am a technologist and product builder dedicated to creating high-impact solutions at the intersection of AI and specialized markets. Currently, I am focused on PropScan (EstateGuard), an AI-driven SaaS platform tailored for the Japanese real estate industry, and exploring the potential of Archify. As an INFJ-T, I approach development with a "systems-thinking" mindset—balancing technical precision with a deep understanding of user needs. I particularly enjoy the challenge of architecting Vertical AI SaaS and optimizing Small Language Models (SLMs) to solve specific, real-world business problems. Whether I'm in a CTO-level leadership role or hands-on with the code, I thrive on building tools that turn complex data into actionable value. Nam Tran Nam Tran 10 years as fullstack developer Antriksh Narang Antriksh Narang 5 years+ Experienced Dev (Specially in Web Development), can help in python, javascript, react, next.js and full stack web dev technologies. Yovel Cohen Yovel Cohen I got a lot of experience in building Long-horizon AI Agents in production, Backend apps that scale to millions of users and frontend knowledge as well. Prakash Prajapati Prakash Prajapati I’m a Senior Python Developer specializing in building secure, scalable, and highly available systems. I work primarily with Python, Django, FastAPI, Docker, PostgreSQL, and modern AI tooling such as PydanticAI, focusing on clean architecture, strong design principles, and reliable DevOps practices. I enjoy solving complex engineering problems and designing systems that are maintainable, resilient, and built to scale. Matthew Butler Matthew Butler Systems Development Engineer @ Amazon Web Services

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

Why can't my app container connect to the database using localhost?

In Docker Compose, each service runs in its own container with its own network namespace. localhost refers to the container itself, not other containers. Use the service name defined in docker-compose.yml (e.g., 'postgres') as the hostname.

How do I wait for the database to be ready before starting my app?

Use depends_on with a health check. Define a healthcheck on the database service (e.g., pg_isready) and set depends_on: postgres: condition: service_healthy on your app service.

Related Claude Code Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help