WordPress and Compose
Learn the configurations needed for Compose to launch WordPress.
We'll cover the following...
Docker Compose configuration
A WordPress project directory named wordpress
is a good choice to have our WordPress-related files in. You’ll be using Docker Compose, so we need a docker-compose.yml
file in the root of the directory. Edit it as:
Press + to interact
version: '3'services:mysql:image: mysql:5container_name: mysqlenvironment:- MYSQL_DATABASE=wpdb- MYSQL_USER=wpuser- MYSQL_PASSWORD=wpsecret- MYSQL_ROOT_PASSWORD=mysecretvolumes:- wpdata:/var/lib/mysqlports:- "3306:3306"networks:- wpnetrestart: on-failurewordpress:image: wordpresscontainer_name: wordpressdepends_on:- mysqlenvironment:- WORDPRESS_DB_HOST=mysql- WORDPRESS_DB_NAME=wpdb- WORDPRESS_DB_USER=wpuser- WORDPRESS_DB_PASSWORD=wpsecretvolumes:- wpfiles:/var/www/html- ./wp-content:/var/www/html/wp-contentports:- "80:80"networks:- wpnetrestart: on-failurevolumes:wpdata:wpfiles:networks:wpnet:
The following sections describe this configuration in detail.
Environment variables
The MySQL environment variables MYSQL_DATABASE
, MYSQL_USER
, and MYSQL_PASSWORD
define a new database named ...