How To Install Wordpress Using Docker (Properly)


Installing WordPress using Docker with Apache and MySQL can be a great way to develop and deploy WordPress sites easily and efficiently. In this step-by-step guide, I will walk you through the process of installing WordPress using Docker with Apache and MySQL.

Step 1. Install Docker and Docker Compose: The first step is to install Docker and Docker Compose on your system. You can find installation instructions for your operating system on the Docker website.

Step 2. Create a New Directory: Create a new directory where you will store the configuration files for your WordPress installation. You can name the directory whatever you like, but for this tutorial, we will call it "wordpress-docker."

Step 3. Create a Docker Compose File: Next, create a Docker Compose file in the "wordpress-docker" directory. You can name the file "docker-compose.yml". In this file, we will define the services required for our WordPress installation. Open the .yml in a text editor and paste:

version: '3' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest ports: - "80:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress volumes: db_data:
This Docker Compose file defines two services, "db" and "wordpress". The "db" service runs a MySQL 5.7 image, while the "wordpress" service runs the latest version of WordPress. The "depends_on" option ensures that the "db" service starts before the "wordpress" service.


Step 4. Start the Docker Containers: To start the containers, navigate to the "wordpress-docker" directory in your terminal and run the following command:

docker-compose up -d

This command will download the required images, create the containers, and start the services in the background. You can check the status of the containers using the following command:

docker ps

This command will display the status of the containers, including the container ID, image name, and port mappings.

Step 5. Configure WordPress: Now that the containers are running, you can configure WordPress by visiting the following URL in your web browser:


This will launch the WordPress installation wizard. Follow the prompts to configure your WordPress site, including setting up a username and password for the admin account.

Step 6. Access the WordPress Site: Once the installation is complete, you can access your WordPress site by visiting the following URL in your web browser:


Congratulations! You have successfully installed WordPress using Docker with Apache and MySQL. You can now develop and deploy WordPress sites easily and efficiently using this setup.