Write down Docker Compose file for WordPress application
To make a WordPress app with Docker Compose, create a docker-compose.yml
file. Here's a simple example with WordPress and MySQL services:
version: '3'
services:
wordpress:
image: wordpress:latest
ports:
- "8000:80"
environment:
WORDPRESS_DB_HOST: mysql
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
volumes:
- ./wordpress:/var/www/html
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: examplepass
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
volumes:
- ./mysql:/var/lib/mysql
In this example:
The
wordpress
service uses the official WordPress image, exposes port 8000 on the host, and sets up environment variables for connecting to the MySQL database. It also mounts a volume to persist WordPress data.The
mysql
service uses the official MySQL 5.7 image, sets up environment variables for configuring the MySQL database, and mounts a volume to persist MySQL data.
To use this configuration:
Create a directory for your WordPress project and navigate to it.
Create the
docker-compose.yml
file with the content above.Run the following command to start the services:
docker-compose up
This will download the required images, create and start the containers.
Access the WordPress site by visiting
http://localhost:8000
in your web browser. Follow the on-screen instructions to set up your WordPress site.
The MySQL data and WordPress content will be saved in the mysql
and wordpress
folders inside your project folder, respectively.
To stop and remove the containers, you can use:
docker-compose down
This is a simple setup, and you can change it more depending on your needs. Always make sure to keep sensitive information (like passwords) safe, especially in production environments.