Fix Docker Compose Warning: 'the attribute version is obsolete, it will be ignored' & Container Refused
Modernize `compose.yaml` to the Compose Specification and fix `localhost` vs service-name networking between containers.
WARN[0000] /app/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
# Remove top-level 'version:' from docker-compose.yml and connect via service name 'db:5432': DATABASE_URL="postgresql://postgres:postgres@db:5432/app" # Check if host port 5432 is conflicting with a local daemon: npx castov port 5432
Root Cause & Mechanism Analysis
Why does this error occur?
Docker Compose v2+ follows the unified Compose Specification where top-level `version: '3.8'` is deprecated. Additionally, containers attempting to connect to `localhost:5432` instead of the Compose service hostname (`db:5432`) fail with `ECONNREFUSED`.
Frequently Asked Questions
Why does `depends_on` alone not wait for PostgreSQL to accept connections?
Need Zero-Knowledge .env Secret Sync Across Your Engineering Team?
Explore Castov Env Vault for client-side AES-256-GCM encrypted environment sharing, or sponsor this engineering hub.
Related Developer Error Solutions
Browse All 54 GuidesDocker: Bind for 0.0.0.0:Port Failed
Identify and terminate conflicting host processes or adjust Docker port mapping to resolve port bind collisions.
Docker: no space left on device
Clean dangling Docker build caches, unused volumes, and stopped containers to free disk space.
Next.js Hydration Failed
Resolve Next.js React hydration mismatch errors caused by browser-only APIs (window, localStorage), timestamps, or invalid HTML nesting.
CORS 'Access-Control-Allow-Origin' Missing
Resolve browser cross-origin resource sharing errors by configuring backend HTTP headers and handling preflight OPTIONS requests.