This guide provides detailed instructions on how to install Docker Desktop on a Windows system with WSL2 and deploy WordPress with a MySQL database using Docker containers.
Part 1: Installing Docker
Steps Followed:
-
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).
-
Verify Docker Installation:
- Open PowerShell and check the Docker version:
docker --version
-
Test Docker functionality by running:
docker run hello-world
Part 2: MySQL and WordPress Containers Deployment
Prerequisites:
- 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
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
-
--name wp-mysql
: Specifies the container namewp-mysql
. -
-e MYSQL_ROOT_PASSWORD=rootpass
: Sets the MySQL root password. -
-e MYSQL_DATABASE=wordpress
: Creates the databasewordpress
. -
-e MYSQL_USER=wpuser
and-e MYSQL_PASSWORD=wppass
: Creates a userwpuser
with the passwordwppass
. -
-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
-
--name wp-wordpress
: Specifies the container namewp-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.
Accessing WordPress
Open your browser and go to:
http://localhost:8080Follow the WordPress setup instructions to finish configuring your site.
Common Docker Commands for Management
Check Running Containers:
docker ps
Stop Containers:
docker stop wp-mysql wp-wordpress
Start Containers:
docker start wp-mysql wp-wordpress
Remove Containers:
docker rm -f wp-mysql wp-wordpress
Remove Volumes:
docker volume rm wp-mysql-data wp-html
This documentation summarizes the process of installing Docker and deploying WordPress and MySQL containers using WSL2 on Windows. With these visual aids and detailed explanations, it should be easier for users to follow along and successfully complete the setup.
Top comments (0)