caddy-docker-proxy works by listening to docker events, and when it
sees a container or service that has a
caddy label will automatically
configure a Caddy Server to proxy that traffic. Caddy takes care of
the TLS certificate so, if you've got a domain name configured to
point to the server, you have an easy way to deploy a container to the
Setup on the server
First you'll need to get yourself a server, and then point some DNS
records to it. I'm going to use
First you need to create a
caddy network. All of your containers
after this should be on the
caddy network and this where the traffic
Then we need to create some volumes to store the caddy data on. This will mainly be the letsencrypt certificates.
Now start it up. Be sure to change the email address – this gets passed to letsencrypt when your certs are generated.
We mount the
docker.sock so that this container can communicate with
the underlying docker server and watch for deploy events. It runs on
caddy network except where we've opened it up on the HTTP and HTTPS ports.
Deploy a container
First we need to build ourselves an image and push it to a repository.
Since I'm on a mac and we are going to deploy on intel hardware, we'll
buildx to build for both architectures. This is on my laptop.
Now we can go back to the server and do:
And we can check out the logs to make sure that it started correct:
Be sure to build for the right architecture!
Make sure that your container starts up correctly, if it doesn't then you won't get the certificates and the errors inside of the caddy container log isn't useful.