Setup WordPress Application using Docker and Docker Network

In this post we will be seeing how we can use Docker Network to launch multiple container in one network and Setup WordPress Application for the same.

Setup and run Mysql

docker run --name mymysql -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7

Now we will add a new database for our WordPress by executing mysql in the container.

$ docker exec -it mymysql mysql -u root -p
mysql> create database wordpress;

Once row’s are affected type exit to exit.

Setup WordPress

$ docker run --name mywordpress -p 8080:80 -d wordpress

Now launch the application using IP:8080 and login, we will be getting error error establishing a database connection. So now let’s fix it, we need to create a new docker network and attach it to both of our containers.

$ docker network create --attachable mynetwork

The above command tells docker to create a new network named wordpress-network that can be manually attached to containers. After the network is created, we can connect it to the containers.

$ docker network connect mynetwork mymysql
$ docker network connect mynetwork mywordpress

Now again go to IP:8080 enter username as root, password as password, database as wordpress and host as mymysql and try setting up! This should work.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s