This is the code that I provided in a blog post that I wrote entitled SSL/TLS with a Traefik Proxy 3.x in a Docker Swarm stack using Let's Encrypt certificates that have already been provisioned.
I created this using traefik:v3.1.4. If you need it for Traefik v2, you should use the docker provider instead of the swarm provider.