c4lab
Follow https://hub.docker.com/_/wordpress/ to make sure WordPress can work on your machine.
In this tutorial, wordpress:5.4.0-php7.2-apache
are used.
You can use certbot to get certification files
docker run --rm -it -p 80:80 -p 443:443 -v $PWD/letsencrypt:/etc/letsencrypt certbot/certbot certonly --standalone
Then copy the certification files out.
cp letsencrypt/live/my.domain.ntu.edu.tw/* certs/
or follow others tutorial if it doesn't work.
Mount some modified files into container.
wordpress:
image: wordpress:5.4.0-php7.2-apache
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- ./wordpress:/var/www/html
- ./certs:/etc/ssl/certs:ro
- ./default-ssl.conf:/etc/apache2/sites-available/default-ssl.conf:ro
- ./docker-entrypoint.sh:/usr/local/bin/docker-entrypoint.sh:ro
ports:
- 443:443
...
(Did not change other things)
./certs
is the folder your certs are.
./default-ssl.conf
is the configuration of port 443 on Apache, recommended to set as follow.
ββ<VirtualHost *:443>
ββ DocumentRoot /var/www/html
ββ ErrorLog ${APACHE_LOG_DIR}/error.log
ββ CustomLog ${APACHE_LOG_DIR}/access.log combined
ββ SSLEngine on
ββ ServerName my.domain.ntu.edu.tw # Change this
ββ SSLCertificateFile /etc/ssl/certs/fullchain.pem # change this
ββ SSLCertificateKeyFile /etc/ssl/certs/privkey.pem # Change this
ββ <FilesMatch "\.(cgi|shtml|phtml|php)$">
ββ SSLOptions +StdEnvVars
ββ </FilesMatch>
ββ <Directory /usr/lib/cgi-bin>
ββ SSLOptions +StdEnvVars
ββ </Directory>
ββ</VirtualHost>
docker-entrypoint.sh
will run before the web server started.
wordpress_wordpress_1
is the container name which wordpress is on, feel free to change it)
βββββdocker cp wordpress_wordpress_1:/usr/local/bin/docker-entrypoint.sh .
docker-entrypoint.sh
.
βββββa2enmod ssl
βββββa2ensite default-ssl
βββββservice apache2 restart
βββββservice apache2 stop
βββββexec "$@"
Tell me if it cannot work.
If you want to split Wordpress main program into FPM and NGINX.
See this repo https://github.com/dbtek/docker-compose-wordpress-fpm-nginx