Running Hybrid Docker Stacks Behind a Single Edge ProxyRunning Hybrid Docker Stacks Behind a Single Edge Proxy
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
The Hybrid Stack: Docker Behind a Single Edge Proxy How to run containers, legacy services and external backends side by side, behind one front door. Most real-world infrastructure is not pure. You may have a shiny set of containerized microservices, a PHP app that has run on the host since 2014, a database on a separate VM, and a SaaS endpoint you need to expose under your own domain. Rewriting everything to fit one deployment model is rarely realistic.
A hybrid stack accepts this. Docker handles the services that benefit from containerization, and a single edge proxy (nginx or Caddy) sits in front of everything, regardless of where each service actually runs. Users see one clean domain with HTTPS. Behind it, you can mix and migrate freely.
This article explains the architecture, shows working configuration for both nginx and Caddy, and covers the practical benefits.
What "Hybrid" Means Here
In this context, hybrid means the proxy fronts a mix of backends:
Containerized apps running in Docker on a shared network.
Host-native services such as a legacy app, a systemd daemon or a dev server on the host machine.
Remote upstreams on another VM, another data center or a cloud provider.
Static content served directly from disk or a volume.
The edge proxy is the only component exposed to the internet (ports 80 and 443). Everything else lives on private networks.
                 Internet
|
[ Edge Proxy ] <- TLS, routing, headers, rate limits
nginx or Caddy (ports 80/443)
/ | | \
[ app ] [ api ] [ legacy ] [ remote VM ]
Docker Docker on host other network
The Building Blocks
1. Docker and Compose
Docker packages each service with its dependencies, and Compose describes how they connect. The key design choice is networks. Create at least two:
A proxy network that the edge proxy shares with any service it needs to reach.
One or more internal networks for private traffic, such as app to database, which the proxy never joins.
This gives you network-level isolation for free: a database is simply unreachable from the proxy or the internet.
2. The Edge Proxy
The proxy terminates TLS, routes by hostname or path, and applies cross-cutting policy (compression, headers, limits, logging). The two common choices:
Caddy is the quickest path to a secure setup. It obtains and renews Let's Encrypt certificates automatically, enables HTTP/2 and HTTP/3, and uses a very short config format.
nginx is the long-standing industry workhorse. It is extremely fast, has a huge ecosystem and offers fine-grained control, at the cost of more verbose configuration and a separate certificate tool such as certbot.
Example: Compose File
Here is a minimal hybrid setup using Caddy:
services:
caddy:
image: caddy:2
ports:
- "80:80"
- "443:443"
- "443:443/udp" # HTTP/3
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
extra_hosts:
- "host.docker.internal:host-gateway"
networks: [proxy]
restart: unless-stopped

web:
image: myorg/web:latest
networks: [proxy, backend]
restart: unless-stopped

api:
image: myorg/api:latest
environment:
DATABASE_URL: postgres://app:secret@db:5432/app
networks: [proxy, backend]
restart: unless-stopped

db:
image: postgres:16
volumes:
- pgdata:/var/lib/postgresql/data
networks: [backend] # never exposed to the proxy
restart: unless-stopped

networks:
proxy:
backend:
internal: true

volumes:
caddy_data:
caddy_config:
pgdata:
Notice that db is only on the internal backend network. The extra_hosts line lets the proxy container reach services running directly on the host via host.docker.internal.
Example: Caddy Routing
example.com {
encode zstd gzip

# Containerized frontend
handle {
reverse_proxy web:3000
}

# Containerized API
handle_path /api/* {
reverse_proxy api:8080
}

# Legacy app running on the host machine
handle_path /legacy/* {
reverse_proxy host.docker.internal:8081
}
}

# Separate hostname for a remote upstream
reports.example.com {
reverse_proxy 10.0.4.12:9000
}
That is the entire config for automatic HTTPS, compression and four backends of three different kinds.
Example: The nginx Equivalent
server {
listen 443 ssl http2;
server_name example.com;

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

gzip on;

location / {
proxy_pass http://web:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /api/ {
proxy_pass http://api:8080/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
}

location /legacy/ {
proxy_pass http://host.docker.internal:8081/;
proxy_set_header Host $host;
}
}
The structure is the same; nginx simply asks you to spell out more details, and you manage certificates yourself.
Dynamic Routing with Labels
Static config works well for small stacks. As the number of services grows, you can let the proxy discover containers automatically:
Caddy has the community caddy-docker-proxy plugin, which builds routes from container labels.
Traefik is another option purpose-built for this.
nginx can do the same with a companion tool like nginx-proxy or a template generator such as docker-gen.
With label-based routing, deploying a new service means adding a few labels to its Compose entry. No proxy file edits, no manual reloads.
Benefits of the Hybrid Stack
A single, secure entry point
Only the proxy listens publicly. Databases, queues and internal APIs are never exposed, which dramatically shrinks your attack surface. Firewall rules become trivial: allow 80 and 443, deny the rest.
Centralized TLS
Certificates live in one place. With Caddy they are issued and renewed automatically; with nginx a single certbot job covers every service. Individual apps never need to know about HTTPS.
Incremental modernization
You do not have to containerize everything at once. Put the legacy app behind the proxy today, containerize it next quarter, and move it to another server after that. The public URL never changes, so users and integrations are unaffected. This is the classic strangler-fig migration pattern.
Consistent environments
Docker gives each service identical behavior across a laptop, staging and production. The same Compose file and proxy config can be promoted between environments with only environment variables changing.
Cross-cutting policy in one spot
Compression, security headers, rate limiting, request size limits, access logs and basic authentication can be applied once at the edge instead of reimplemented in every application and language.
Easy zero-downtime changes
You can bring up a new version of a service, point the proxy at it, and retire the old one. Reloads in both nginx and Caddy are graceful, so in-flight requests are not dropped.
Flexible deployment topology
Because the proxy simply forwards to addresses, it does not care whether the target is a container, a host process or a machine across a VPN. The same pattern scales from a single cheap VPS to a multi-node setup.
Low cost and low overhead
Both nginx and Caddy are lightweight. A small server can comfortably front many services, which makes this stack attractive for startups, side projects, homelabs and internal tools.
Good observability
One proxy means one place for access logs and metrics. Request rates, latencies and error codes for every service can be gathered without touching application code.
Best Practices
Use separate Docker networks. Join the proxy only to the networks of services it must reach.
Never publish backend ports. Avoid ports: on apps and databases; let only the proxy expose ports.
Pin image versions. Prefer specific tags over latest for reproducible deployments.
Forward the right headers. Preserve Host, client IP and protocol so applications behave correctly behind the proxy. Caddy does much of this by default; nginx needs explicit proxy_set_header lines.
Add health checks. Use Docker healthcheck entries and consider proxy-level health checks for upstreams.
Persist certificate storage. Keep Caddy's /data volume (or your certbot directory) on durable storage to avoid hitting certificate rate limits.
Mind WebSockets and streaming. Caddy handles them automatically; in nginx you must set the Upgrade and Connection headers and tune buffering.
Back up volumes and configs. Keep proxy config and Compose files in version control.
Choosing Between nginx and Caddy
Consideration | Caddy | nginx
HTTPS setup | Automatic | Manual (certbot or similar)
Config size | Very concise | More verbose
Performance | Excellent for most workloads | Excellent, battle-tested at massive scale
Ecosystem | Growing | Very large
Advanced tuning | Good | Extensive
Learning curve | Gentle | Steeper
A reasonable rule of thumb: choose Caddy when you value simplicity and automation, and nginx when you need deep tuning, specific modules or already have nginx expertise on the team.
Limitations to Keep in Mind
The proxy is a single point of failure unless you add redundancy, such as multiple proxy instances with a load balancer or floating IP.
Docker on a single host has limits. For many nodes, automated failover and large-scale scheduling, an orchestrator like Kubernetes or Nomad may be more appropriate.
Host networking quirks. Reaching host services from containers varies slightly by platform (host.docker.internal works out of the box on Docker Desktop but needs host-gateway on Linux).
Config drift. Mixing static proxy config with label-based discovery can get confusing; pick one approach per environment.
Conclusion
The hybrid stack is a pragmatic architecture: Docker for packaging and isolation, a single edge proxy for security, routing and policy, and the freedom to put each workload wherever it makes sense. It lets you modernize at your own pace, keeps your attack surface small, and stays simple enough to understand and operate with a small team.
If you are starting out, begin with Caddy and a two-network Compose file, route one containerized app and one legacy service through it, and grow from there. You can always swap in nginx or add an orchestrator later, since the shape of the architecture stays the same.
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started