These examples assume the use of docker-compose
to run Caddy. It’s possible to do this configuration other ways, in which case it can be adapted to your preferred method.
Socketed (Recommended)
This method is probably the simplest. It works for single and multisite Discourse installs in single and multiple container modes, including:
-
Default: Standalone single-site (
app.yml
) -
Dual container single-site (
web_only.yml
withdata.yml
) -
Dual container multi-site (
web_only.yml
withdata.yml
) - Multiple standalone container multi-site (e.g.,
app.yml
+site1.yml
+site2.yml
) - Multiple container single-database multi-site (e.g.,
web_only.yml
+web1.yml
+web2.yml
withdata.yml
)
Caddyfile:
forum.example.com {
reverse_proxy unix//sock/app/nginx.http.sock
}
Caddyfile for dual container multisite
forum.example.com, forum2.example.com, forum3.example.com {
reverse_proxy unix//sock/web_only/nginx.http.sock
}
Discourse config (app.yml
or web_only.yml
):
- Add to templates section
- "templates/web.socketed.template.yml"
- Comment out or remove SSL templates
# - "templates/web.ssl.template.yml"
# - "templates/web.letsencrypt.ssl.template.yml"
- Comment out or remove ports
# - "80:80" # http
# - "443:443" # https
-
Add a line to volumes in
docker-compose
(maps volumes to socket)
volumes:
- ${DISCOURSE_PATH}/shared:/sock
# - /var/discourse/shared:/sock # <---Default location
example docker-compose.yml
version: '3.3'
# DISCOURSE_PATH and CADDY_PATH come from .env in this example.
# Adjust them accordingly to your environment /var/www/caddy, etc.
services:
caddy:
image: caddy
ports:
- "80:80"
- "443:443"
- "80:80/udp"
- "443:443/udp"
volumes:
- ${DISCOURSE_PATH}/shared:/sock
- ${CADDY_PATH}/caddy/Caddyfile:/etc/caddy/Caddyfile
- ${CADDY_PATH}/var/caddy:/root/.caddy
- ${CADDY_PATH}/caddy/data:/data
- ${CADDY_PATH}/caddy/config:/config
restart: always
Notes
- The
./discourse-setup
script requires ports 80 and 443 to be open and unassigned by Docker. So if you’re using that script, you’ll need to stop the Caddy container. After the script completes, you can switch to socketed,/launcher rebuild app
, then restart the Caddy container.
Docker Ports (Alternate Method)
Arguably not as fast as socketed (though the practical difference may be zero), using ports is the more common way of interacting with Docker. Because of that, you may find that it is better documented, and therefore “easier” to implement in edge-cases.
Caddyfile (assuming app.yml
)
forum.example.com {
reverse_proxy app:80
}
Discourse config ( app.yml
or web_only.yml
):
- Set Discourse to listen on non-standard Docker port
- "8880:80" # http
- Comment out or remove SSL templates
# - "templates/web.ssl.template.yml"
# - "templates/web.letsencrypt.ssl.template.yml"
- Get Caddy and Discourse on the same Docker network:
expose:
- "8880:80" # http
# - "443:443" # https
# Use 'links' key to link containers together, aka use Docker --link flag.
links:
- link:
name: caddy
alias: caddy
# any extra arguments for Docker?
docker_args:
- '--network caddy_default'
networks:
caddy_default:
external: true
Notes
- The
./launcher
script expects thenetwork
to be running while thebootstrap
orrebuild
runs.