Hosting a web site or blog, that is visible in the internet and made searchable by search engine providers, should be always up to date and properly secured.
Installation
First we look into the installation and configuration process inside a docker environment. The root folder for docker containers is /opt, followed by the configuration name, in our case wordpress.
Create Directories
sudo mkdir /opt/wordpress && cd /opt/wordpress sudo mkdir mariadb_data wordpress_data sudo chown -R 33:33 mariadb_data wordpress_data
We can split the docker configuration and the user credentials by using an extra file for some environment variables.
.env File
MYSQL_ROOT_PASSWORD=<your root password> MYSQL_USER=<your username> MYSQL_PASSWORD=<your password>
docker-compose.yml file
For easier backup and recovery, it is possible to map the important container directories to the host system disk.
services:
mariadb:
image: mariadb:latest
container_name: wordpress-mariadb
restart: always
env_file:
- .env
environment:
- MYSQL_DATABASE=wordpress
volumes:
- ./mariadb_data:/var/lib/mysql
networks:
- wordpress-db-network
wordpress:
image: wordpress:latest
container_name: wordpress-app
depends_on:
- mariadb
restart: always
ports:
- "8082:80"
environment:
- WORDPRESS_DB_HOST=mariadb:3306
- WORDPRESS_DB_USER=$MYSQL_USER
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
- WORDPRESS_DB_NAME=wordpress
volumes:
- ./wordpress_data:/var/www/html
networks:
- wordpress-db-network
networks:
wordpress-db-network:
driver: bridge