Hi all,
I’m new to docker and gained few experience with it.
I have an opnsense firewall with caddy as reverse proxy to propagate a let’s encrypt wildcard certificate to my services. I want to use caddy in a docker container in order to encrypt the services with this certificate. But I’m not sure how to add the external proxy caddy in the docker-compose.yml file.
As an example for practising purposes i want to setup the passwordmanager vaultwarden on my docker host:
The template looks like this
What do I have to change that this container uses my caddy proxy running on my firewall to get the let’s encryot certificate?
I think i have to start with a configuration similar to this, am i on the right way?
vaultwarden.mydomain.com {
reverse_proxy IP:port (IP of my firewall)
tls {
protocols tls1.3
}
}
If Caddy and the target container (e.g. Vaultwarden) run on the same docker engine, you could use container labels that would be picked up by Caddy through observing the docker engines event stream, finding labels it knows and applies them dynamically as configuration in memory.
Since your Caddy is not running on the same docker engine, it can not access the event stream and you have to configure everything in Caddy directly.
Nothing you configure on the container will help you to configure caddy. you need to configure your caddy settings manually to take care of this. The LE certificate will exist on your Caddy host. https traffic needs to be send to caddy, which terminates the tls context and sends everything unencrypted to your Vaulwarden container using the host-ip:published-host:port for your container.
and I would note that this doesn’t seem to be correct:
If caddy is running on the firewall and other containers are not, the IP and port should be the target IP where the containers are running. And also instead of
as @meyay already pointed out, you could not connect to the proxy network, but you would need to forward a port to make the container available to the proxy:
services:
vaultwarden:
ports:
- 8080:80
Assuming the target service (vaultwarden here) in the container is listening on port 80 and the proxy can access the service on port 8080 on the host IP of the machine where vaultwarden is running.