Docker Compose is a popular open-source tool that is used to define and run multi-container Docker applications. In this article, we will guide you through the process of installing WordPress with Docker Compose on Ubuntu 20.04.
Before we begin, make sure that you have a fresh installation of Ubuntu 20.04 and that Docker and Docker Compose are installed on your system. You will also need to be logged in as a user with sudo
privileges.
Create a new Docker Compose file
The first step is to create a new Docker Compose file for WordPress. This file will define the containers, volumes, and networks for your WordPress application. To create the file, run the following command in the terminal:
sudo nano docker-compose.yml
In the file, add the following configuration:
version: '3.1'
services:
wordpress:
image: wordpress:5.5.1
ports:
- 8080:80
volumes:
- ./wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: password
depends_on:
- db
db:
image: mysql:8.0
volumes:
- ./db-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
This configuration defines two Docker containers: one for WordPress and one for MySQL. It also defines the volumes and environment variables for each container. Save the file and exit the editor.
Download WordPress
Next, we need to download the WordPress files to the current directory. To do this, run the following command in the terminal:
wget <https://wordpress.org/latest.tar.gz>
tar xfz latest.tar.gz
mv wordpress/wp-content .
This will download the WordPress tarball and extract the “wp-content” directory to the current directory.
Start the containers
After creating the Docker Compose file and downloading the WordPress files, we can start the containers using the following command:
sudo docker-compose up -d
This will download the necessary Docker images and start the containers in the background.
Access WordPress
After the containers are started, you can access WordPress by opening a web browser and navigating to **http://localhost:8080**.
You will see the WordPress installation wizard where you can complete the installation and setup process.
Stop the containers
To stop the containers, run the following command in the terminal:
sudo docker-compose down
This will stop the containers and remove their associated volumes and networks.
By following these steps, you should have successfully installed WordPress with Docker Compose on your Ubuntu 20.04 system.