Using caddy docker proxy
straight from the dockerfiles
- tags
- docker
- caddy
- caddy-docker-proxy
Contents
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
internet.
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 apple.willschenk.com
and
banana.willschenk.com
.
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
will go.
|
|
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
the 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
use 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:
|
|
Troubleshooting
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.
Previously
Next