509.949.2162 jeremy@bondbyte.com

Using Docker for hosting WordPress and Mariadb container seems like a no brainer. The container allows sites to be managed, maintained and moved without disrupting the other sites.

We will need a nix box in the cloud, static IP is a must. We should probably create a docker account so we can save images but not required. Obviously we will need WordPress and Mariadb but we also need a Reverse Proxy. The reverse proxy will handle request routing making sure the right request find the correct WordPress Container. Since we’re using a Reverse Proxy we will also need to generate our SSL Certs on the proxy. For that we will use a Docker Nginx Lets Encrypt Reverse Proxy project. A mouth full.

Step 1:

First, lets create a Docker Network for our containers to talk over. We will call this wpn-main. Notice the –net switch in the docker commands, we’re adding everything to the wpn-main docker network.

docker network create wpn-main

Step 2:

Create the Nginx Proxy

docker run --name nginx-proxy --net wpn-main -p 80:80 -p 443:443 -v ~/certs:/etc/nginx/certs -v /etc/nginx/vhost.d -v /usr/share/nginx/html -v /var/run/docker.sock:/tmp/docker.sock:ro --label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy -d --restart always jwilder/nginx-proxy

Step 3:

Connect to Nginx-proxy container and tweak the nginx.conf file to accommodate larger file uploads. Before we do that tho, we will need to add a text editor.

Connect to the Nginx Docker Container

docker exec -it nginx-proxy bash

Okay, we’re connected but we’re going to need a text editor. Lets grab nano.

apt-get update
apt install nano

Now that we have our editor lets go tweak the nginx.conf.

nano /etc/nginx/nginx.conf

Add the client_max_body_size parameter to the conf file http {} section.

http{
    ...
    client_max_body_size 128M;
    ...
}

We’ve tweaked the max body size, lets restart Nginx.

service nginx restart

Exit the container

Exit

Step 4:

Create the Let Encrypt Nginx Proxy Companion

docker run --name letsencrypt-nginx-proxy-companion --net wpn-main -v ~/certs:/etc/nginx/certs:rw -v /var/run/docker.sock:/var/run/docker.sock:ro --volumes-from nginx-proxy -d --restart always jrcs/letsencrypt-nginx-proxy-companion

Step 5:

Create the a Mariadb container for our web instance. Swap the red text with your own. wbpe_site1. I like to name my containers after their role. wpbe meaning WordPress Backend.

docker run --name wpbe-site1 --net wpn-main -e MARIADB_ROOT_PASSWORD=rootpassword -e MARIADB_USER=user -e MARIADB_PASSWORD=userpassword -e MARIADB_DATABASE=wordpressdb -d --restart always mariadb

Step 6:

Create the WordPress Frontend Container, we’re calling it wpfe_site1. swap the red text with your swaps from step 5:

docker run --name wpfe-site1 --net wpn-main -e WORDPRESS_DB_HOST=wpbe-site1:3306 -e WORDPRESS_DB_NAME=wordpressdb -e WORDPRESS_DB_USER=user -e WORDPRESS_DB_PASSWORD=userpassword -e VIRTUAL_HOST=www.site1.com,site1.com -e LETSENCRYPT_HOST=www.site1.com,site1.com -e LETSENCRYPT_EMAIL=user@site1.com -d --restart always wordpress

Step 7:

Configure up your domain A records. One for the root domain and one for www. The A Record will point to the docker host IP.

Notes:

Here are some helpful commands.

List all containers

docker ps -a

A better more narrow list. The “ps -a” above shows all the columns

docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}\t{{.Ports}}"

List all images

docker images

List all networks

docker network ls

Stop docker container

docker stop containername

Start docker container

docker start containername

Connect to docker container (type exit to close bash)

docker exec -it containername bash

Remove docker container container must be stopped first

docker rm containername

Remove docker network see List all Networks command

docker network rm networkname

Save docker container to docker image. used for reuse and cloning.

docker commit containername newimagename

Copy Files between host OS and Docker image. This is used to copy files from the Host OS to a container. Different than creating a Volume.

docker cp ./somefile ContainerName:/somelocation

Copy Files from Docker image to host OS. This is how you copy the other way, from Docker down to Host OS.

 docker cp ContainerName:/var/logs/ /tmp/app_logs

List top 100 Log Entries from a Docker Container

docker logs -n 100 <containername>

Docker Resource Monitor (ctrl+c to close)

docker logs -n 100 letsencrypt-nginx-proxy-companion

Credits

Credit goes to a few sites I borrowed some concepts from. This link for setting up reverse proxy even though part of it is wrong.

Here’s a good getting started with docker and WordPress

https://towardsdev.com/wordpress-mysql-simple-docker-project-c64dc0f9c695

And here’s another

https://www.sitepoint.com/how-to-manually-build-docker-containers-for-wordpress/

Thoughts

I should probably build a container and add some items to the container and create a new image.

Some of those items being

Yeost SEO or some sort of SEO

WordFence

WPS Hide Login

Updraft Plus

Site Kit by Google