Setting Up WordPress with MariaDB Using Docker
Introduction:
WordPress is a popular content management system for building websites and blogs. In this guide, we’ll show you how to set up WordPress with MariaDB (MySQL database) using Docker, allowing you to easily create and manage your website.
Step 1: Install and Run MariaDB Container
To install MariaDB and run it in Docker, use the following command:
docker run -e MYSQL_ROOT_PASSWORD=wordpress -e MYSQL_DATABASE=wordpress \
--name wordpressdb -v mariadb_data:/var/lib/mysql -d mariadb:latest
Explanation of options used:
-e MYSQL_ROOT_PASSWORD=wordpress
: Set the root password for the MariaDB database to “wordpress”.-e MYSQL_DATABASE=wordpress
: Create a database named “wordpress” for the WordPress installation.--name wordpressdb
: Assign the name “wordpressdb” to the MariaDB container for easy management.-v mariadb_data:/var/lib/mysql
: Create a Docker volume named “mariadb_data” and mount it to the “/var/lib/mysql” directory inside the container. This volume allows you to persist MariaDB’s data.
Step 2: Install and Run WordPress Container
To install WordPress and run it in Docker, use the following command:
docker run -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=wordpress \
--name wordpress --link wordpressdb:mysql -p 80:80 -v wordpress_data:/var/www/html -d wordpress:latest
Explanation of options used:
-e WORDPRESS_DB_USER=root
: Set the WordPress database user to “root” (linked to the MariaDB container).-e WORDPRESS_DB_PASSWORD=wordpress
: Set the WordPress database password to “wordpress” (linked to the MariaDB container).--name wordpress
: Assign the name “wordpress” to the WordPress container for easy management.--link wordpressdb:mysql
: Link the WordPress container to the MariaDB container, allowing WordPress to connect to the database.-p 80:80
: Map port 80 from the container to port 80 on the host system. This allows you to access WordPress athttp://localhost
.-v wordpress_data:/var/www/html
: Create a Docker volume named “wordpress_data” and mount it to the “/var/www/html” directory inside the container. This volume allows you to persist WordPress’s data.
Conclusion:
By following these steps and using Docker, you have successfully set up WordPress with MariaDB on your system. You can now access and manage your WordPress website by visiting http://localhost
in your web browser.
Enjoy creating and managing your WordPress website with ease using Docker! Happy blogging!