I use docker compose, dns validation through cloudflare, and wildcard DNS. I try to do all configuration through docker-compose.yml. Everything works correctly. I can access the traefik dashboard, and all docker services with labels configured are properly redirected. I am now trying to add basic auth to protect access to the dashboard.
I generated a user account and hashed password using
htpasswd -nBC 10 admin mypassword
I then created a /credentials.txt file and put the info in there.
admin:mylonghashedpassword
I then appended the following lines to the labels section of my traefik container:
I recreate traefik container, but I can still access the dashboard without a prompt for user/password. Super frustrating! Any advice would be very appreciated.
Solved! This post was extremely helpful in figuring this out.
Here is how to recreate my setup for anyone in a similar boat later!
Features of my setup:
Docker-Compose.yml based configuration (no separate files!)
Cloudflare DNS Validation
Wildcard Cert Generation for subdomains
Redirect to HTTPS
Basic Auth via declared credentials file (this avoids the $$ vs $ drama)
volume declaration -- I dont think you need quotes around:
"/configs/traefik/credentials.txt:/credentials.txt:ro" -- I think it can be:
/configs/traefik/credentials.txt:/credentials.txt:ro
Next your labels are kind of distracting however I think its something like:
Appreciate the help! I actually figured it out. I did a full write up, and posted it as a reply. It's still being reviewed by mods though. Maybe because it was pretty lengthy and I'm new to the forums.
Good work! I still want to point you to two great Traefik posts that really made me click:
The biggest difference is that he uses the static file, Traefik.yml for the stuff that should reside there, IMHO.
That makes the other files so much easier to read, and thus understand.
Cool thanks! I tried the Traefik.yml route, but found it less convenient personally. With this approach I can integrate the traefik compose commands straight into my portainer stack. Makes it easy for me to make adjustments on the fly, instead of manually editing files.
What you are missing is that the changes in the traefik.yml file is automatically picked up by Traefik. Having them in the docker-compose file means you have to restart the container to pickup the changes.
Traefik has both a static and dynamic configuration setup. Changes made within the static configuration file are not dynamically picked up, where as the changes made in the dynamic configuration file are automatically picked up without have to restart containers. I'm aware this "split" of configuration files seems like a pain, however it just fits into the traefik definition of things.