I am new to Traefik and I coming from a Docker Flow Proxy background. I am trying to run Traefik 2.0 as a docker swarm service. Here is the command I am using...
The part in Bold Font doesn't seem to be working. Can that not be added as command line option or am I using the wrong options?
Here is the error I am getting from the Traefik container:
command traefik error: failed to decode configuration from flags: field not found, node: tls
What am I doing wrong?
Or as an alternative, is there a default location I can put the certificates in and it just works automagically? That way I wouldn't have to specifiy the location.
What you pass on the command line is static configuration. Allowed options are documented here. However TLS options are dynamic configuration, not static. It's documented here.
To quote:
Restriction
In the above example, we've used the file provider to handle these definitions. It is the only available method to configure the certificates (as well as the options and the stores).
So it appears, that you are going to have to use the File Provider to pass this configuration.
So I added a traefik.yml file and put it on the top level directory. I added this option to the docker service create command "--providers.file.filename=/traefik.yml". Here are the contents of the traefik.yml file.
This is another time that I'm confused by the way the Traefik team/docs use English. I want a dynamic configuration - in some environments it would be LetsEncrypt in another environment it would be self-signed. However, that does not seem possible. "Dynamic," in my view, should encapsulate certificate type. But if some certificate types are static only, then that aspect isn't really dynamic, right?
You can use custom TLS and LetsEncrypt without a problem. For certs from file, just load the certs in a dynamic configuration and set TLS=true or TLS: {} on entrypoint or router. For LetsEncrypt set certresolver on entrypoint or router.
You could also use LE for dev, you can use dnsChallenge to get certs for (wildcard) domains that are not available on the Internet, only internal.
The problem is, I want to be able to switch from one environment variable like LETSENCRYPT_ENABLE=true and fallback on using local cert if false.
I am able to make it work if I delete my dynamic configuration while using letsencrypt, but it is cumbersome to make a volume optional with docker compose, I would need to do an override file.
Also, I thought about using a resolver for my local files so I could use something like TRAEFIK_RESOLVER=letsencrypt and TRAEFIK_RESOLVER=local in my environment but it doesn't look like it's possible.
I would love to see an elegant way to manage this if someone have done it already