domain configuration in docker-compose
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Domain configuration in Docker Compose usually means mapping friendly hostnames to services during local development and staging. Docker networking already provides service-name DNS inside the Compose network, while browser-accessible custom domains usually require host mapping and a reverse proxy. A clean setup improves local parity with production routing.
Understand Internal Versus External Domain Resolution
Inside a Compose network, containers can resolve each other by service name.
Here, web can call http://api:8080 without extra DNS configuration.
External access from your laptop browser is different. Host OS needs to resolve names such as app.local to local proxy endpoints.
Basic Compose Hostname and Aliases
You can set container hostname and network aliases for internal discovery.
These aliases work inside Docker network scope, not automatically on your host machine.
Configure External Domains with Reverse Proxy
For realistic domain routing, use Traefik or Nginx as front proxy and route by host header.
Compose example with Traefik:
Then map domain in host file:
Now browser requests to http://app.local route to the correct container via Traefik.
Multi-Service Domains and Subdomains
You can route multiple services by subdomain.
Host mappings:
This mirrors production-style host-based routing with separate services.
HTTPS in Local Compose Environments
For local TLS testing, use mkcert or self-signed certs and configure proxy TLS entrypoints.
Example concepts:
- generate local trusted certs,
- mount cert files into proxy container,
- configure router TLS options.
This helps test secure cookie behavior, OAuth callbacks, and mixed-content rules earlier.
Useful DNS and Networking Diagnostics
When domain routing fails, inspect three layers:
- host name resolution,
- proxy route rules,
- container network connectivity.
Helpful commands:
Inside container DNS checks:
These quickly isolate whether issue is DNS, routing config, or service health.
Local DNS Alternatives to Manual Host File Edits
For teams with many services, manual host-file entries do not scale well. Lightweight local DNS tools such as dnsmasq can route wildcard domains like *.dev.local to 127.0.0.1.
Typical approach:
- map wildcard local domain to loopback,
- configure reverse proxy to route by host header,
- use consistent subdomain conventions per service.
This reduces setup friction for new developers and keeps local domain rules consistent across projects.
Document the chosen local domain convention in project onboarding notes so everyone uses the same URLs and proxy rules.
Common Pitfalls
A common mistake is expecting Compose network aliases to work from host browser. They only resolve inside Docker networks unless host DNS is configured.
Another issue is forgetting host file entries for local custom domains. Without explicit mapping, requests never reach local proxy.
Developers also bind multiple proxies to port 80 simultaneously, causing hidden startup failures. Ensure a single component owns each host port.
Summary
- Compose service names provide internal DNS automatically.
- External custom domains require host mapping and usually a reverse proxy.
- Use proxy host-based rules for multi-service local routing.
- Add TLS locally when testing security-sensitive flows.
- Debug by checking host DNS, proxy rules, and container connectivity in order.
Related reading
- dotnet core app api do not keep running on kubernetes
- Downgrade kubectl version to match minikube k8s version
- During local development with Kubernetes/minikube, how should I connect to postgres database running on localhost?
- Dynamic deployment of stateful applications in GKE
- Dropping container with RabbitMQ in Docker
- Dynamically get a running container id/name created by docker run command
- Download an already uploaded Lambda function
- Duplicate log output when using Python logging module

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.