Copy letsencrypt files to docker container

Solution 1:

You did everything right, the problem is with the files. If you look at them, you'll see that they're not normal files but links:

root@fbe56bc38ad6:/# ls /etc/letsencrypt/live/example.com/ -l
total 4
-rw-r--r-- 1 root root 692 Jul 24  2020 README
lrwxrwxrwx 1 root root  44 Mar 22 00:03 cert.pem -> ../../archive/example.com/cert5.pem
lrwxrwxrwx 1 root root  45 Mar 22 00:03 chain.pem -> ../../archive/example.com/chain5.pem
lrwxrwxrwx 1 root root  49 Mar 22 00:03 fullchain.pem -> ../../archive/example.com/fullchain5.pem
lrwxrwxrwx 1 root root  47 Mar 22 00:03 privkey.pem -> ../../archive/example.com/privkey5.pem
lrwxrwxrwx 1 root root  42 Mar  1 12:57 example.com -> /etc/letsencrypt/live/example.com
lrwxrwxrwx 1 root root  33 Mar  1 12:57 ssl-dhparams.pem -> /etc/letsencrypt/ssl-dhparams.pem

And so you mounted a bunch of relative links that point to a non-existent location.

I suggest you mount /etc/letsencrypt to /etc/letsencrypt in container:

    volumes:
      - /etc/letsencrypt:/etc/letsencrypt

Then make your application to look for files in /etc/letsencrypt/live/example.com or make another link at /static/ssl that points to /etc/letsencrypt/live/example.com:

ln -s /etc/letsencrypt/live/example.com /static/ssl