Step 1. Install Docker and Docker Compose: The first step is to install Docker and Docker Compose on your system. You can find installation instructions for your operating system on the Docker website.
Step 2. Create a New Directory: Create a new directory where you will store the configuration files for your WordPress installation. You can name the directory whatever you like, but for this tutorial, we will call it "wordpress-docker."
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data:
This Docker Compose file defines two services, "db" and "wordpress". The "db" service runs a MySQL 5.7 image, while the "wordpress" service runs the latest version of WordPress. The "depends_on" option ensures that the "db" service starts before the "wordpress" service.
Step 4. Start the Docker Containers: To start the containers, navigate to the "wordpress-docker" directory in your terminal and run the following command:
Step 5. Configure WordPress: Now that the containers are running, you can configure WordPress by visiting the following URL in your web browser:
Step 6. Access the WordPress Site: Once the installation is complete, you can access your WordPress site by visiting the following URL in your web browser: