In this guide, you will learn how to set up and use WordPress with Docker Desktop using Docker Compose. Using this method will make you stop using XAMPP, LAMP or WAMP.
Prerequisites
Before proceeding, make sure you have the following prerequisites installed on your system:
- Docker Desktop: Download and install Docker Desktop from the official Docker website for your operating system.
Step 1: Create a Docker Compose file
- Open your favorite text editor such as VS Code.
- Create a new file named
docker-compose.yamlin the directory of your choice. - Copy and paste the following content into the
docker-compose.yamlfile and then make sure to save the file:
version: '3.8'
services:
db:
# We use a mariadb image which supports both amd64 & arm64 architecture
image: mariadb:10.6.4-focal
# If you really want to use MySQL, uncomment the following line
# image: mysql:8.0.27
command: '--default-authentication-plugin=mysql_native_password'
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=somewordpress
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=wordpress
expose:
- 3306
- 33060
wordpress:
image: wordpress:latest
ports:
- 80:80
restart: always
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
volumes:
db_data:
Step 2: Start the WordPress container
- Open Docker Desktop on your system.
- In the Docker Desktop interface, navigate to the folder where you saved the
docker-compose.yamlfile. - Click on the "Compose" button in the Docker Desktop interface.
- Select the
docker-compose.yamlfile you created. - Click on the "Run" button to start the WordPress container.
Docker Desktop will pull the required images and start the containers.
Step 3: Access WordPress in your browser
- Open your web browser.
- Enter the following URL in the address bar:
http://localhost
Follow the WordPress installation steps to set up your website and then you're good to go. It will be fully functional.
Step 4: Stop and remove the containers
If you want to stop and remove the WordPress containers, follow these steps:
- Open Docker Desktop on your system.
- In the Docker Desktop interface, navigate to the folder where you saved the
docker-compose.yamlfile. - Click on the "Compose" button.
- Select the
docker-compose.yamlfile. - Click on the "Stop" button to stop the containers.
Docker Desktop will stop and remove the containers, but it will retain the WordPress database and its data.
Congratulations! You have successfully set up WordPress using Docker Desktop and Docker Compose. You can now manage and customize your WordPress website within the Docker environment.
Remember to regularly backup your WordPress data to avoid data loss, and refer to the Docker documentation for more advanced configuration options and deployment scenarios.
The Docker Compose code is taken from the docker/awesome-compose github repository which contains many different templates for docker-compose.

Top comments (0)