How to install WordPress on Docker (Windows) along with phpMyAdmin

What Exactly Is Docker?

Docker is an open-source containerization software that creates isolated environments to run an application. Hence, you develop, test, and run multiple applications on the same machine.

In contrast to virtual machines, each container does not require its own OS and shares the host’s kernel. Thus, the machine’s workload is far more lightweight and a single server can run multiple containers at the same time.

For that reason, Docker is highly useful for WordPress developers. A WordPress test environment usually eats up a lot of system resources, but Docker helps them make a minimal environment without wasting server space and memory.

https://www.hostinger.com/tutorials/run-docker-wordpress

How to Install Docker on Windows?

Follow the steps below to install Docker:

  1. Enable Hyper-V in your system.
  2. Download Docker Desktop for Windows and open the Docker for Windows Installer file.
  3. In the Configuration dialog window, check or uncheck the boxes based on your preferences. Click Ok.
  4. Once the installation is finished, hit Close. You’ll see the Docker icon in the taskbar.

How to Install WordPress with phpMyAdmin on Docker?

After successful installation of Docker we have to set up environment to install WordPress.

Next, let’s set up WordPress on Docker. You can do this process with these two methods ‒ the CLI and Docker compose.

In this article, we’ll be using Docker compose, the cleaner and more systematic method. Here’s how:

Step 1: Check Docker Compose Installation:

docker-compose --version

Step 2: Create a new directory for WordPress:

mkdir ~/wordpress/
cd ~/wordpress/

Step 3: Create a new docker-compose.yml in the new directory and paste the content below. Don’t forget to change the credentials.

version: '3.3'
services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: hello-root
      MYSQL_DATABASE: wp-db
      MYSQL_USER: wp-user
      MYSQL_PASSWORD: wp-pass

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    environment:
      PMA_HOST: db
      MYSQL_USER: wp-user
      MYSQL_PASSWORD: wp-pass
      MYSQL_ROOT_PASSWORD: hello-root
    ports:
      - 3001:80

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wp-user
      WORDPRESS_DB_PASSWORD: wp-pass
      WORDPRESS_DB_NAME: wp-db
volumes:
  db_data: {}

Step 4: Run this command in the directory to create the containers:

docker-compose up -d

Note: If you already installed WordPress on Docker and then try to access phpMyAdmin then add following code into your previously created docker-compose.yml file (if previously not configured phpMyAdmin).

phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    environment:
      PMA_HOST: db
      MYSQL_USER: wp-user
      MYSQL_PASSWORD: wp-pass
      MYSQL_ROOT_PASSWORD: hello-root
    ports:
      - 3001:80

Step 5: Your browser will enter localhost:8000 and display the WordPress setup screen.

Leave a Comment