Hi,
I have just found Traefik this week. I was referred to take a look at it by someone on the Docker Slack Channel. Frankly, I think it's pretty fascinating, and I really want to propose that we use it to terminate SSL for an upcoming docker based tomcat + websockets app deployment, where the websockets containers are orchestrated dynamically by the tomcat application. I thought that with Traefik, I could save the developers the complication of building SSL into their applications and containers. I have only looked at Traefik V2, thinking that it's best to start with the current version.
I have had good luck over the past couple of days setting up some reference examples with Traefik V2 using HTTP. Basically setting up Traefik to proxy to either my own container and/or the whoami container. From this reference example I am trying to get to using HTTPS instead of HTTP and failing miserably. I have looked over these links, but am not able to successfully force the use of HTTPS with the whoami container:
https://docs.traefik.io/https/tls/#user-defined
https://docs.traefik.io/migration/v1-to-v2/#tls-configuration-is-now-dynamic-per-router
https://docs.traefik.io/migration/v1-to-v2/#http-to-https-redirection-is-now-configured-on-routers
Can someone tell me how where I'm going wrong in my configs below? I need SSL to run on port 8443, as there is already software binding to port 443 on my test machine. Using the curl
commands from the examples, I should be able to do this:
$ curl -k -H Host:whoami.docker.local -L http://127.0.0.1/
and receive the whoami output after redirection to https://127.0.0.1:8443/, but what I get is:
curl: (6) Could not resolve host: whoami.docker.local
Here is my config details:
docker-compose.yml:
version: '3'
services:
reverse-proxy:
image: traefik:latest
command:
- --api.insecure=true
- --providers.docker
- --entrypoints.web.address=:80
- --entrypoints.web-secured.address=:8443
- --entrypoints.traefik.address=:8080
- --providers.file.directory=/config
- --log.level=debug
labels:
- traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https
- traefik.http.middlewares.redirect-to-https.redirectscheme.port=8443
- traefik.http.routers.redirs.rule=hostregexp(`{host:.+}`)
- traefik.http.routers.redirs.entrypoints=web
- traefik.http.routers.redirs.middlewares=redirect-to-https
ports:
- "8080:8080"
- "8443:443"
- "80:80"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./config:/config:ro
- ./certs/:/certs:ro
whoami:
image: containous/whoami
labels:
- traefik.enable=true
- traefik.http.routers.whoami.rule=Host(`whoami.docker.local`)
- traefik.http.routers.whoami.entrypoints=web-secured
- traefik.http.routers.whoami.tls=true
To create the certs I have done the following:
$ mkdir certs
$ openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/privkey.key -x509 -days 365 -out certs/cert.crt
...using whoami.docker.local
as the certificate's CN. I've tried other names to no success.
To create the config dir:
$ mkdir config
$ cat << EOF > config/certs.toml
[[tls.certificates]]
certFile = "/certs/cert.crt"
keyFile = "/certs/privkey.key"
[tls.stores]
[tls.stores.default]
[tls.stores.default.defaultCertificate]
certFile = "/certs/cert.crt"
keyFile = "/certs/privkey.key"
EOF
Thanks for taking a look, I welcome any help or suggestions.