Docker · Containers in practice

How do you put a reverse proxy in front of containers?

Mediumreverse proxytlsnginxUpdated Oct 2026
Quiz this track

Short answer

Run a proxy such as nginx, Traefik or Caddy on a shared network, route by host or path to service names, terminate TLS there, and forward the correct client headers.

The proxy is the only service that publishes ports 80 and 443. Application containers stay on an internal network and are reached by service name. This centralises TLS, routing, compression and request limits.

nginx
server {
  listen 443 ssl;
  server_name api.example.com;

  ssl_certificate /etc/letsencrypt/live/api/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/api/privkey.pem;

  location / {
    proxy_pass http://api:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_read_timeout 60s;
  }
}
api resolves through the Compose network, so no host port is needed for the app.

Things that bite

  • WebSocket upgrades need explicit Connection and Upgrade headers
  • Large uploads need a body size limit and a longer timeout
  • The app must trust forwarded headers only from the proxy
  • TLS certificates need renewal and a reload strategy
  • Health checks should target the proxy and the app separately

Traefik and Caddy can discover containers through labels or the Docker API and manage certificates automatically. That reduces configuration, but it also means the proxy needs access to the Docker socket or a discovery mechanism, which is a security consideration.

If the proxy and app are on different networks, name resolution fails even though both containers are running. Attach both to the shared network.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why should the application not publish a host port when a proxy is used?
  2. 2What headers must the proxy forward for correct client IPs?
  3. 3How do you support WebSockets through the proxy?
  4. 4What is the security concern with Docker label discovery?

Say it in the interview

I run a reverse proxy on a shared Docker network and let it own ports 80 and 443, while application containers stay internal and are reached by service name. The proxy terminates TLS and forwards Host, X-Forwarded-For and X-Forwarded-Proto. I also configure WebSocket headers, upload limits and certificate renewal, because those are the usual causes of production surprises.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Docker mock interview and get scored feedback on depth, clarity and confidence.