Make a docker instance serve SSL (https)
- Get link
- X
- Other Apps
Enabling SSL on an Apache Docker Instance
Step 1 – Enable SSL inside the container
docker exec -it <container_name> bash
a2enmod ssl socache_shmcb
Step 2 – Copy SSL certificate and key from host to container
On the host, use the actual files from /etc/letsencrypt/archive/
(not the symlinks in live/
):
docker cp /etc/letsencrypt/archive/mysite.com/fullchain30.pem <container_name>:/etc/ssl/certs/mysite.crt
docker cp /etc/letsencrypt/archive/mysite.com/privkey30.pem <container_name>:/etc/ssl/private/mysite.key
Step 3 – Edit Apache vhost to use SSL
Inside the container:
vi /etc/apache2/sites-enabled/000-default.conf
Replace content with:
<VirtualHost *:80> SSLEngine on ServerName www.mysite.com ServerAlias mysite.com SSLCertificateFile /etc/ssl/certs/mysite.crt SSLCertificateKeyFile /etc/ssl/private/mysite.key DocumentRoot /var/www/html/dockerhtml/ DirectoryIndex index.html index.php </VirtualHost>
Step 4 – Allow Apache to serve from non-default path
Edit:
vi /etc/apache2/apache2.conf
Append:
<Directory /var/www/html/dockerhtml/>Options Indexes FollowSymLinks Require all granted </Directory> possibly also to the default <Directory /> entry as well.
Step 5 – Set a global ServerName
At the top of /etc/apache2/apache2.conf
:
ServerName www.mysite.com
to get rid of the FQDN complaint
Step 6 – Reload Apache without killing the container
apache2ctl -k graceful
Your Docker-hosted Apache is now serving HTTPS on the mapped port using your Let’s Encrypt certificate from the host.
- Get link
- X
- Other Apps