How to Create a Docker Compose File for WordPress and MariaDB

Are you looking to set up a WordPress website with a MariaDB database using Docker? Docker provides a convenient way to create and manage containers, allowing you to run applications in isolated environments. In this tutorial, we’ll guide you through the process of creating a Docker Compose file for WordPress and MariaDB.


Before we begin, make sure you have Docker and Docker Compose installed on your system. You can download them from the official Docker website.

Step 1: Create a New Directory

Start by creating a new directory for your project. Open a terminal and run the following command:

$ mkdir wordpress-mariadb

Step 2: Create a Docker Compose File

Next, navigate to the newly created directory:

$ cd wordpress-mariadb

Now, create a new file called docker-compose.yml using your preferred text editor:

$ nano docker-compose.yml

Within this file, you’ll define the services for WordPress and MariaDB.

Step 3: Configure MariaDB

First, let’s configure the MariaDB service. Add the following code to your docker-compose.yml file:

version: '3'
			image: mariadb
			restart: always
				MYSQL_ROOT_PASSWORD: your_mysql_root_password
				MYSQL_DATABASE: your_wordpress_database
				MYSQL_USER: your_wordpress_user
				MYSQL_PASSWORD: your_wordpress_user_password

Make sure to replace your_mysql_root_password, your_wordpress_database, your_wordpress_user, and your_wordpress_user_password with your desired values.

Step 4: Configure WordPress

Next, let’s configure the WordPress service. Add the following code below the MariaDB configuration:

		- db
	image: wordpress
	restart: always
		- 8080:80
		WORDPRESS_DB_NAME: your_wordpress_database
		WORDPRESS_DB_USER: your_wordpress_user
		WORDPRESS_DB_PASSWORD: your_wordpress_user_password

Again, replace your_wordpress_database, your_wordpress_user, and your_wordpress_user_password with the appropriate values.

Step 5: Start the Containers

Save the docker-compose.yml file and close the text editor. In the terminal, run the following command to start the containers:

$ docker-compose up -d

This command will pull the necessary Docker images (if not already available) and start the WordPress and MariaDB containers in detached mode.

Step 6: Access Your WordPress Site

Once the containers are up and running, you can access your WordPress site by opening a web browser and navigating to http://localhost:8080. You should see the WordPress setup page where you can configure your site.


By following these steps, you’ve successfully created a Docker Compose file for running WordPress with a MariaDB database. Docker provides a convenient and reproducible way to set up and manage your WordPress environment. Feel free to customize the configuration to suit your specific requirements.





Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.