caddyserver / caddyserver/website

[Docs] Specify that using reverse_proxy for Docker containers should utilize the *internal* container port

Open
#453 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
227
Forks
213
Avg merge
3h 52m
Merged PRs (30d)
1

Description

I have been scrambling to figure out why my local Docker Compose setup utilizing Caddy as a reverse proxy wasn't working and it all boiled down to a single, simple Caddyfile change (using the internal container port instead of the host port).

Link to relevant docs: https://caddyserver.com/docs/running#docker-compose
Link to forum post coment that gave the proper solution: https://caddy.community/t/caddy-foundry-docker-connection-issues/21265/2

I hope this breakdown helps others who may have been banging their heads against the same problem.

I was under the impression that my Caddyfile should look like:

...
localhost {
	reverse_proxy app:3030 <--- <container name>:<host machine port>
}
...

With a Dockerfile like:

caddy:
    ...
    restart: unless-stopped
    environment:
      - ACME_AGREE=true
    volumes:
      - /caddy/Caddyfile:/etc/caddy/Caddyfile
      - /caddy/site:/srv
      - caddy_data:/data
      - caddy_config:/config
    ports:
      - 80:80
      - 443:443
      - 443:443/udp
    depends_on:
      - app
app:
    ...
    container_name: app
    ports:
      - 3030:3000
    restart: unless-stopped

But that just resulted in my app being unreachable. In reality all I needed was to utilize the internal container port that was being used by the app.

So my Dockerfile could look like:

caddy:
    ...
    restart: unless-stopped
    environment:
      - ACME_AGREE=true
    volumes:
      - /caddy/Caddyfile:/etc/caddy/Caddyfile
      - /caddy/site:/srv
      - caddy_data:/data
      - caddy_config:/config
    ports:
      - 80:80
      - 443:443
      - 443:443/udp
    depends_on:
      - app
app:
    ...
    container_name: app
   ### Don't even need to bind ports
    # ports:
     #  - 3030:3000
    restart: unless-stopped

With a Caddyfile like:

...
localhost {
	reverse_proxy app:3000<--- <container name>:<internal container port>
}
...

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Docker Compose section of the running documentation at https://caddyserver.com/docs/running#docker-compose and compare its reverse_proxy example with the supplied Caddyfile and Compose snippets. Update the explanation to distinguish the internal container port from the host-mapped port, and ensure the example reflects that distinction.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, docker-compose
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.