Another Side quest for helping friend in his assignment
Containerizing-wordpress-app
and migrating the database
Old files
Dockerfile for wordpress
docker-compose file
mysql docker file
myPassw0rd
‘wpuser123’@‘localhost’ IDENTIFIED BY ‘wpuserPassw0rd’;
|Site Title|wp-testsite| |Username|wpwebuser | |password|)5S@PsG1J$VACnJ@%Q| |email|[email protected]| |||
Docker mariadb password wpuser123Passw0rd
#exporting/backuping old mysql data
mysqldump -u wpuser123 -pwpuserPassw0rd new_db > dump.sql
#current mysql configuration
mysql user: wpuser123
mysql passwd: wpuserPassw0rd
db name: new_db
#login to ec2 and run the backup command
mysqldump -u wpuser123 -p new_db > mywpold_db.sql
steps
- create new folder in wordpress cd into it
mkdir wordpress && cd wordpress
-
pull wordpress and mariadb containers
sudo docker pull wordpress
sudo docker pull mariadb
-
create custom docker network
sudo docker network wp-app
sudo docker network ls
-
Creation of mariadb database container
- hash the password of db first
echo `openssl passwd` | sudo tee $PWD/.db-pass
now hashed password file must be in .db-pass
file
here i have set myPassw0rd
password
cat .db-pass
$1$Nyql5zO2$H9e0n0m44qJ8xQfPt79Pn0
- Create mariaDB data directory to mount container database with /var/lib/mysql
sudo mkdir -p data
~/wordpress
- data
- Create and run Mariadb Docker container
sudo docker run -d --network=wp-app -e MARIADB_ROOT_PASSWORD_HASH=/home/ubuntu/wordpress/.db-pass --restart unless-stopped -v '/home/ubuntu/wordpress/data:/var/lib/mysql' --name wp-mariadb mariadb
- check health and logs
docker ps
sudo tail -f /var/lib/docker/containers/<container-ID>/<container-ID>-json.log
example:
sudo tail -f /var/lib/docker/containers/8c07234611094796605b37b5822255dcdd35aa4325e7729aa2ff5c8be6dcefa6/8c07234611094796605b37b5822255dcdd35aa4325e7729aa2ff5c8be6dcefa6-json.log
- check mounted volume for generated data
ls -1 data
regarding migration of old database
copy the backup file into container db folder
cp mywpold_db.sql wordpress/data/
- login to mariadb container
docker exec -it wp-mariadb bash
restore old db
cd /var/lib/mysql
mariadb -u wpuser123 -p new_db < mywpold_db.sql;
REFERENCES:
- https://kifarunix.com/how-to-deploy-wordpress-as-a-docker-container/
- https://mariadb.com/kb/en/moving-mariadb-to-docker-installation/#comment_3811
- https://mariadb.com/kb/en/backup-and-restore-overview/
- https://www.reddit.com/r/docker/comments/tj8qp2/containerize_an_existing_wordpress_site/?rdt=49217