I need to caching static resources (js, css, html, images, etc...) with my Docker Swarm cluster. I see that Traefik doesn't have this feature.
I've seen a lot of threads talking about file caching with Nginx, Varnish, Hitch, etc... and I don't quite know which system to choose for this purpose.
Which is the best configuration for caching resources with a scenario with Docker Swarm multi node and Traefik as a load balancer?
I'm sure there will be some optimal settings to caching resources with Traefik in Swarm mode.
Thanks in advance.
Hi @sergarrido, as you already and correctly guessed, Traefik's role is not about caching resources and not serving files as a web server would do.
The "classic" setup in Docker Swarm would be:
- Traefik responsible for routing requests from outside to inside
- A web server (Nginx, Varnish, whatever) responsible for caching
Traefik would see the web server as a backend service.
=> Then you would have to decide: "what is the condition on requests that would make Traefik send requests to this backend?" . it can be based on the host, on path, on header's value or cookies value.
I recommend you to start with Traefik v2.0 (as this topic is currently on the Traefik v1 section):
Then, the "caching" part is a matter of the tools you want to choose. Nginx could be a good start: https://www.nginx.com/blog/nginx-caching-guide/.
My recommendation is to "split" concerns. Try avoiding putting all features on the same application: routing requests and caching file are 2 different things!
Thanks for your information.
Finally, I’ve decided to add HAProxy before Docker Swarm Cluster and install Varnish for caching static resources.
I’ve used this map:
Thanks for all.