How to migrate WordPress website using Git and Docker

There are cases where you want to migrate your website environment to a different environment.
This knowledge describes the procedure for migrating a website environment created with Docker and WordPress using Git.
The migration target environment has a configuration similar to the environment described in the following knowledge.

This procedure describes the website environment as the migration target, but if the environment uses Docker and Docker Compose, the environment can be migrated by the same procedure.

 

Sponsored Links
You have been blocked from seeing ads.

How to get the environment from the source environment

Get the website environment using WordPress from the migration source environment.
This procedure describes the procedure using Git. However, if the target directory and files can be migrated, there is no problem even if you compress the files to zip etc. without using Git and migrate the files.

The following procedure is performed on the migration source server side.

  • Stop the environment with “docker_compose” in order to acquire the static cross section of the database of the WordPress environment.
  • Execute the “docker_compose” command where the docker-compose.yml file exists.
$ cd ~/web/top/docker_compose/

$ docker-compose stop

Stopping docker_compose_wordpress_1 ... done
Stopping docker_compose_db_1        ... done

 

  • Check that the environment has stopped.
$ docker-compose ps
           Name                         Command                State     Ports
------------------------------------------------------------------------------
docker_compose_db_1          docker-entrypoint.sh mysqld      Exit 0  
docker_compose_wordpress_1   docker-entrypoint.sh apach ...   Exit 137 

 

  • In an environment that uses Docker and Docker Compose, basically docker-compose.yml and the volumes directory used in it are the entire environment. So get that directory and files.
    • As long as you have acquired docker-compose.yml, which is the design drawing of WordPress, you can build the same environment in the migration destination environment based on it.
    • Updated files such as WordPress themes are stored in “/ var / www / html” of the virtual server for WordPress. Therefore, it is necessary to get “./volumes/wordpress/html” which is the directory where the area is mounted by “volumes”.
    • Updated files such as WordPress articles are stored in “/ var / lib / mysql” of the virtual server for database. Therefore, it is also necessary to acquire “./volumes/db_data” which is the directory where the area is mounted by “volumes”.
$ ls ~/web/top/docker_compose/
docker-compose.yml           volumes

$ ls ~/web/top/docker_compose/volumes/
db_data  wordpress

 

  • Upload the target directory and file to the remote repository with Git.
    • In the following example, the work tree of Git is “~/git_repo/pj01_repo01”.
    • If the target directory and file can be obtained, there is no problem even if the file is migrated by compressing it to zip etc. without using Git.
$ sudo cp -rfp ~/web/top/docker_compose/* ~/git_repo/pj01_repo01/
$ cd ~/git_repo/pj01_repo01/
$ sudo git add *
$ git push -u origin master

 

  • If necessary, start the migration source website.
$ cd ~/web/top/docker_compose/

$ docker-compose start

 

How to set up the environment in the migration destination environment

Set the Docker environment acquired in the previous step in the migration destination environment.
 
The following procedure is the procedure to be performed on the migration destination server side.
  • Use Git on the migration destination server side as well. Therefore, if you have not installed Git yet, install and set Git by referring to the following knowledge. However, if you can put the target directory and files, there is no problem even if you do not use Git.

 

  • GDownload the required directories and files from the remote repository uploaded in the previous step using Git.
$ mkdir ~/git_repo
$ cd ~/git_repo
$ git clone ssh://[User]@[FQDN]:[port][Absolute path of repository]

 

  • If you have already executed “git clone” in the past and want to update the local repository only, execute pull under the work tree with the following command.
$ cd ~/git_repo/pj01_repo01
$ git checkout master
$ git pull origin master

 

  • Place the downloaded directory and files in the same directory as the migration source.
$ mkdir -p ~/web/top/docker_compose
$ cd ~/web/top/docker_compose/
$ sudo cp -prf ~/git_repo/pj01_repo01/* ~/web/top/docker_compose/

 

Start the website environment in the migration destination environment

 

  • Change the owner to “www-data” so that the WordPress related files in the migrated files will be managed by WordPress.
$ cd ~/git_repo/pj01_repo01
$ ls
docker-compose.yml           volumes

$ sudo chown -R www-data:www-data volumes/wordpress/html
$ ls -l volumes/wordpress/
total 4
drwxrwxr-x 5 www-data www-data 4096 Dec 27 01:28 html

 

  • Start the WordPress environment with Docker Compose.
$ sudo docker-compose up -d

 

This completes the website startup and the migration is complete.
Check the website by accessing the URL of the migration destination environment such as “http://localhost/” or “http://[public IP]”.

Sponsored Links
You have been blocked from seeing ads.