DEV Community

Victor Okonkwo
Victor Okonkwo

Posted on

Installing Docker and Deploying WordPress with MySQL

Part 1: Installing Docker

Steps Followed:

  1. Install Docker Desktop:
    • Download Docker Desktop from the official Docker website.
    • Follow the installation prompts to install Docker Desktop.
    • Enable WSL 2 integration during the installation process to integrate Docker with the Ubuntu distribution on WSL (if used).

Docker Desktop Installation

  1. Verify Docker Installation:

    • Open PowerShell and check the Docker version:
     docker --version
    
  • Test Docker functionality by running:

     docker run hello-world
    

Docker Hello World


Part 2: MySQL and WordPress Containers Deployment

Prerequisites:

  • MySQL already installed on your system.
  • Docker Desktop is up and running.

Run MySQL and WordPress Containers in a Single Command:
You can run both containers simultaneously using a single line in PowerShell:

docker run --name wp-mysql -e MYSQL_ROOT_PASSWORD=rootpass -e MYSQL_DATABASE=wordpress -e MYSQL_USER=wpuser -e MYSQL_PASSWORD=wppass -v wp-mysql-data:/var/lib/mysql -p 3306:3306 -d mysql:5.7 && docker run --name wp-wordpress -e WORDPRESS_DB_HOST=wp-mysql:3306 -e WORDPRESS_DB_USER=wpuser -e WORDPRESS_DB_PASSWORD=wppass -e WORDPRESS_DB_NAME=wordpress -v wp-html:/var/www/html -p 8080:80 --link wp-mysql:mysql -d wordpress:latest
Enter fullscreen mode Exit fullscreen mode

Explanation of Commands:

MySQL Container:

docker run --name wp-mysql \
  -e MYSQL_ROOT_PASSWORD=rootpass \
  -e MYSQL_DATABASE=wordpress \
  -e MYSQL_USER=wpuser \
  -e MYSQL_PASSWORD=wppass \
  -v wp-mysql-data:/var/lib/mysql \
  -p 3306:3306 \
  -d mysql:5.7
Enter fullscreen mode Exit fullscreen mode
  • --name wp-mysql: Specifies the container name wp-mysql.
  • -e MYSQL_ROOT_PASSWORD=rootpass: Sets the MySQL root password.
  • -e MYSQL_DATABASE=wordpress: Creates the database wordpress.
  • -e MYSQL_USER=wpuser and -e MYSQL_PASSWORD=wppass: Creates a user wpuser with the password wppass.
  • -v wp-mysql-data:/var/lib/mysql: Creates a volume for MySQL data persistence.
  • -p 3306:3306: Maps MySQL's port 3306 to the host machine.
  • -d: Runs the container in detached mode.

WordPress Container:

docker run --name wp-wordpress \
  -e WORDPRESS_DB_HOST=wp-mysql:3306 \
  -e WORDPRESS_DB_USER=wpuser \
  -e WORDPRESS_DB_PASSWORD=wppass \
  -e WORDPRESS_DB_NAME=wordpress \
  -v wp-html:/var/www/html \
  -p 8080:80 \
  --link wp-mysql:mysql \
  -d wordpress:latest
Enter fullscreen mode Exit fullscreen mode
  • --name wp-wordpress: Specifies the container name wp-wordpress.
  • -e WORDPRESS_DB_HOST=wp-mysql:3306: Points WordPress to the MySQL container (wp-mysql).
  • -e WORDPRESS_DB_USER, -e WORDPRESS_DB_PASSWORD, -e WORDPRESS_DB_NAME: Credentials for connecting WordPress to MySQL.
  • -v wp-html:/var/www/html: Creates a volume for WordPress files.
  • -p 8080:80: Maps port 80 inside the container to port 8080 on the host machine.
  • --link wp-mysql:mysql: Links the WordPress container to the MySQL container.

Part 3: Accessing WordPress

  1. Open your browser and go to:
   http://localhost:8080
Enter fullscreen mode Exit fullscreen mode
  1. Follow the WordPress setup instructions to finish configuring your site.

WordPress Setup


Common Docker Commands for Management

Check Running Containers:

docker ps
Enter fullscreen mode Exit fullscreen mode

Stop Containers:

docker stop wp-mysql wp-wordpress
Enter fullscreen mode Exit fullscreen mode

Start Containers:

docker start wp-mysql wp-wordpress
Enter fullscreen mode Exit fullscreen mode

Remove Containers:

docker rm -f wp-mysql wp-wordpress
Enter fullscreen mode Exit fullscreen mode

Remove Volumes:

docker volume rm wp-mysql-data wp-html
Enter fullscreen mode Exit fullscreen mode

This documentation summarizes the process of installing Docker and deploying WordPress and MySQL containers.

Top comments (0)