Deploying WordPress using a Docker network
In this recipe, we will learn to use a Docker network to set up a WordPress server. We will create two containers, one for MySQL and the other for WordPress. Additionally, we will set up a private network for both MySQL and WordPress.
How to do it…
Let's start by creating a separate network for WordPress and the MySQL containers:
A new network can be created with the following command:
$ docker network create wpnet
Check whether the network has been created successfully with
docker network ls
:$ docker network ls
You can get details of the new network with the
docker network inspect
command:$ docker network inspect wpnet
Next, start a new MySQL container and set it to use
wpnet
:$ docker run --name mysql -d \ -e MYSQL_ROOT_PASSWORD=password \ --net wpnet mysql
Now, create a container for WordPress. Make sure the
WORDPRESS_DB_HOST
argument matches the name given to the MySQL container:$ docker run --name wordpress -d -p 80:80 \ --net wpnet\ -e WORDPRESS_DB_HOST...