Skip to content

Restore 'database' DNS alias on the postgres compose service#224

Merged
edimossilva merged 2 commits into
mainfrom
fix-database-hostname-alias
May 7, 2026
Merged

Restore 'database' DNS alias on the postgres compose service#224
edimossilva merged 2 commits into
mainfrom
fix-database-hostname-alias

Conversation

@edimossilva
Copy link
Copy Markdown
Member

Summary

The `database` service in `backend/docker-compose.yml` declares `hostname: database-app-container`. On some Docker / Compose / DNS resolver combinations, that explicit hostname is registered as the only DNS name on the network — the default service-name alias gets dropped — so `web` and `sidekiq` containers can no longer resolve `database`, the value the `.env` file (and `config/database.yml`) expects.

This adds an explicit `networks.default.aliases` entry so both `database` and `database-app-container` resolve to the same container, regardless of how the DNS layer behaves. `redis` and `elasticsearch` are unaffected — `redis` already happens to use its service name as the hostname, and `elasticsearch` has no `hostname:` line so it picks up the default alias automatically.

Test plan

  • `docker compose up -d` (no other env tweaks)
  • `docker compose exec web getent hosts database` returns an IP
  • `docker compose exec web getent hosts database-app-container` returns the same IP
  • `docker compose exec web bin/rails db:migrate` connects successfully without setting `POSTGRES_HOST` overrides

🤖 Generated with Claude Code

edimossilva and others added 2 commits May 7, 2026 17:46
The database service declares hostname: database-app-container, which on
some Docker/Compose versions causes the embedded DNS to register *only*
that hostname and drop the default service-name alias. Result: web and
sidekiq containers cannot resolve "database" (the value used in
backend/.env's POSTGRES_HOST), even though "database-app-container"
works. Adding an explicit network alias keeps both names resolvable
without changing the .env contract.

Verified: getent hosts database / database-app-container both return
the same IP, and bin/rails runner can SELECT 1 without POSTGRES_HOST
overrides.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@edimossilva edimossilva merged commit d1a026c into main May 7, 2026
2 checks passed
@edimossilva edimossilva deleted the fix-database-hostname-alias branch May 7, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant