Store the self-signed certificate in a defined location

During development, each time the docker stack starts, a new self-signed certificate is generated. It prompts security warnings on each client application that tries to use them.

I would like to store the self-signed certificate on a volume, so that for each upcoming docker-compose the same certificate would be used.

My current configuration:

# http.yml - self-signed

http:
  routers:
    to-http-to-https:
    rule: "Host(`localhost`)"
    service: nginx
    tls: {}

As you can see a new certificate is generated each time.

For Let's Encrypt certificates, I set up a resolver with a storage path. But how to do the same for an auto-generated and self-signed certificate?

Here an example of Let's Encrypt configuration that stores the certificate inside a json file:

# http.yml - acme
http:
  routers:
    to-http-to-https:
    rule: "Host(`localhost`)"
    service: nginx
      tls:
        certResolver: myresolver

# traefik.yaml - acme
certificatesResolvers:
  myresolver:
    acme:
      email: ...
      storage: /my-storage-location/acme.json
      caServer: ...
      # caServer: ...
      tlsChallenge: {}

Hello,

https://docs.traefik.io/v2.1/https/tls/#user-defined

Thanks, I already use this technique to provide my own certificates. But what I am asking here, is how to store the auto-generated certificate in a given location.

The certificates generated by Traefik cannot be stored.