How to install WordPress with Docker

Source:- techrepublic.com

ocker is an incredibly powerful and flexible tool that allows you to serve up containerized applications such that they are encapsulated and much easier to deploy. I want to demonstrate how easy this is by installing WordPress via Docker.

I will be working on the Ubuntu 16.04 Server platform and will assume you already have Docker up and running. If you don’t have Docker up and running, see “How to install Docker on Ubuntu 16.04” to find out how to install the world’s most popular container platform.

Let’s get to the installation.

Install and set up the database container

Since WordPress relies upon a database, we’ll install MariaDB via Docker and then create the necessary database. The first thing that must be done is to open up a terminal window and pull the latest MariaDB container with the command:

sudo docker pull mariadb

Once the container has been successfully pulled, you must first create a few directories to house the WordPress data. This is done with the following commands (we’ll create the directory in /opt).

sudo mkdir /opt/wordpress
​sudo mkdir -p /opt/wordpress/database
​sudo mkdir -p /opt/wordpress/html

Next we create the MariaDB container with the command:

docker run -e MYSQL_ROOT_PASSWORD=XXX -e MYSQL_USER=wpuser -e MYSQL_PASSWORD=XXX -e MYSQL_DATABASE=wordpress_db -v /opt/wordpress/database:/var/lib/mysql --name wordpressdb -d mariadb

Where XXX are strong passwords to be used for the MySQL root user and the MySQL wpuser account.

The above command will create the wpuser account and create the WordPress database, wordpress_db

Next we need to find out what IP address is associated with our new container. Issue the command:

docker inspect -f '{{ .NetworkSettings.IPAddress }}' wordpressdb

The command will reply with the IP address for your container (Figure A).

Figure A

Figure A

Finding the IP address of your MariaDB docker container.

You can now connect to MySQL on that address with the command:

mysql -u wpuser -h IP_ADDRESS -p

Where IP_ADDRESS is the actual address for the container. You’ll be prompted for the password you created for the wpuser; enter that and the MySQL prompt will appear. Exit out of that prompt by typing exit; and you’re ready to move on.

Install WordPress

Now we must pull down the latest version of WordPress. This is done with the following command:

docker pull wordpress:latest

Allow that pull to complete and then create the new container with the command:

docker run -e WORDPRESS_DB_USER=wpuser -e WORDPRESS_DB_PASSWORD=XXX -e WORDPRESS_DB_NAME=wordpress_db -p 8081:80 -v /opt/wordpress/html:/var/www/html --link wordpressdb:mysql --name wpcontainer -d wordpress

Where XXX is the password for the wpuser you created earlier.

At this point you can now point a browser to http://SERVER_IP:8081 and begin the standard WordPress installation. Where SERVER_IP is the IP address of the server hosting docker, not the container address. Congratulations, you’ve just deployed your WordPress container.

The simplicity of containers

As you can see, containers are actually quite simple to deploy (even with the added complexity of having to connect with a database server). With a few commands you can have a containerized WordPress deployment up and running, thanks to Docker.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x