Use docker to build a wordpress website

Overview

The advantage of using docker is to minimize the environment deployment, strong reliability, and easy maintenance. The main goals of using docker to build wordpress are as follows. First, I regenerate the database container to ensure that the database data is not lost, and regenerate the wordpress container to ensure the wordpress website. No data is lost, try to keep the two containers in stateless operation, and all data are stored locally for easy backup and recovery

mysql container aspect

First of all, I did this experiment on the Raspberry Pi. I used the mysql image of the arm version made by others. In fact, it is the same as the official mysql image. There is no difference, but the name is different. The command to generate the container docker run --name mysql-wordpress -d -v /root/mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD="woyaoxuehuilinux" hypriot/rpi-mysqlExplain , --name is to name the container. -d is to run it in the background, -v plus the following directory means to map the /var/lib/mysql directory in the container and the /root/mysql-data directory in the host, and save the database data locally , the parameter added after -e is to set the password of mysql, and finally the name of the mirror used

wordpress container aspect

run parameters directlydocker run --name wordpress -d -p 80:80 --link mysql-wordpress:mysql -v /root/wordpress-html:/var/www/html wordpress

Let's first explain the parameters --name is to name the container, -d is to run the container in the background -p means that the port 80 of the container is mapped with the port 80 of the host --link means that it is connected to the mysql container just generated , -v means to map the directory of the website to /root/wordpress-html in the host, and finally the name of the mirror to be used

test

If you pull the image and execute the above run command, the ip that directly accesses the host should be the wordpress selection language installation interface, follow the process to install wordpress, and then we publish an article, then we stop and delete the mysql container docker stop mysql-wordpress docker rm mysql-wordpressAfter visiting the website Error establishing a database connection, it means that it cannot connect to the database, which means that it is normal. After that, we re-created the mysql container command in Yunxiang. docker run --name mysql-wordpress -d -v /root/mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD="woyaoxuehuilinux" hypriot/rpi-mysqlThen visit the website and find that the website can be accessed normally. Then the test continues. We delete the database container and the website container and docker stop mysql-wordpress wordpress docker rm mysql-wordpress wordpressthen visit The website, at this time, the website must not be accessible. After that, we recreate these two containers docker run --name mysql-wordpress -d -v /root/mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD="woyaoxuehuilinux" hypriot/rpi-mysql docker run --name wordpress -d -p 80:80 --link mysql-wordpress:mysql -v /root/wordpress-html:/var/www/html wordpressand then visit the website to witness the miracle. The website can be accessed normally, and the data is not lost.

How to backup website?

From the above, we can summarize the steps of backing up the website. First, save the two commands to execute the container to a text file, and then pack mysql-dataand wordpress-htmlbackup the backup. The startup time of the container is only a few seconds, so if you want to do a For a secure website architecture, you can do this, save the two directories I mentioned above in the storage, the container runs on the server, or use k8s to manage the container. Of course, the storage also needs to be backed up, so as long as the service can be guaranteed Super reliable.

Welcome to follow Bboysoul's blog www.bboysoul.com Have Fun

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324982408&siteId=291194637