Migrate a WordPress site from EC2 to a Docker Container
In this post — In this post i will try to explain how i moved my wordpress site from EC2 into a docker container again hosted back on EC2. There will be a lot of questions how different it is, as at the end both are hosted on EC2. I will also try to answer it in this post.
In this post i will try to explain how i moved my wordpress site from EC2 into a docker container again hosted back on EC2. There will be a lot of questions how different it is, as at the end both are hosted on EC2. I will also try to answer it in this post.
Dockerizing your site makes it easy to port to any server and spinning up the application in few minutes.
To perform this, you will have to have a Docker installed in your local machine. I already have installed Docker in my local.
Replace your site url to your local host url,so as to make the wordpress site work locally before replacing back to original site url.
Fix any broken links/url.
Create a single Docker Compose file to dowload wordpress docker image and mysql docker image to create respective docker containers.
Run your wodpress site from the container locally.
You can migrate this container back to a new EC2 and host your site via a container — This is not part of this post, but will be part of my next post.
Migrate WordPress to Docker Container:
It is advised to turn-off or disable all your plugins before starting the migration process on your wordpress. However if you wish to go with your plugins you can still export and install the plugins in your local to address any issues.
Export MySql Database from RDS
Login into EC2 server — CLI and perform below,
[ec2-user@ip-10-0-5-71 ~]$ sudo su [root@ip-10-0-5-71 ec2-user]# bash [root@ip-10-0-5-71 ec2-user]# mysqldump -h yourdb.aws.dnsname.com -u mysqldb_user_name -p schema_name > awsontop_DBDUMP.sql Enter password: [root@ip-10-0-5-71 ec2-user]# ls -lrt awsontop_DBDUMP.sql -rw-r--r-- 1 root root 10441099 Mar 27 23:16 awsontop_DBDUMP.sql
There are multiple ways to move this database export dump file into your local. I have used S3 here to move the file from EC2 to S3 and from there to my local.
To move the files to S3, create a new bucket. I have created ‘awsontopbackup’ bucket and executed below cli at ec2 ,