The following is going to be a step-by-step tutorial on how you can carry out WordPress installation in your local system using docker-compose. It’s going to be a comprehensive and easy to follow guide that will set up your WordPress installation in just a few simple steps.
Step 1: Setting up the Project Directory and Creating the docker-compose.yml File:
- Create a new directory for your project. You can name it whatever you like, for example, “wordpress-docker”.
Figure 1 Make Directory
- Inside the project directory, create a new file named docker-compose.yml.
Figure 2 Create docker-compose file
3. Open the docker-compose.yml file with a text editor and paste the following code:
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: farhan@1
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: farhan@1
wordpress:
image: wordpress:latest
ports:
- 8000:80
restart: always
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: farhan@1
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wp_data: {}
- Save the changes to the file.
Step 2: Running the Docker Compose Command to Start the WordPress Application
Run the following command while staying the “wordpress-docker” directory to start the Docker containers:
Figure 3 Using ‘docker-compose up’ command
This command will create and start the containers defined in the docker-compose.yml file in detached mode.
Step 3: Accessing the WordPress Installation Page in a Web Browser
- Open your web browser.
- Enter the following URL in the address bar:
http://localhost:8000 This will take you to the WordPress installation page.
Step 4: Completing the WordPress Installation Process
- Select your preferred language and click on the “Continue” button.
Figure 4 WordPress Language Select Screen
- On the next screen, you’ll be asked some information to be used for the WordPress installation, fill in the required fields.
Figure 5 Enter Basic Info
- Fill in the required information for your WordPress site, including site title, username, password, and email address.
- Click on the “Install WordPress” button to proceed.
Step 5: Verifying the Successful Deployment of the WordPress Application
- After the installation is complete, you’ll see a success message. Click on the “Log in” button to access your WordPress dashboard.
Figure 6 Login to WordPress
- Enter the username and password you created during the installation process and click on the “Log in” button.
- If you’ve successfully logged in, you’ll be redirected to the WordPress dashboard, indicating that the WordPress application has been deployed successfully using Docker Compose.
Figure 7 WordPress Admin Panel
Figure 8 Actual Site’s Sample Page
That’s it! You’ve successfully deployed a WordPress application with MySQL using Docker Compose. You can now start customizing your WordPress site and creating content.