How do I move data into a container- Part 2: the Setup

This is the second in a series of posts focusing on extending and enhancing the previously ‘Dockerized’ WordPress installation – specifically focused on the movement / migration of data for the newly containerized application.

As I mentioned in How do I ‘containerize’ something, part 3: Getting Ready, I already have a copy of the necessary files for my ‘production’ WordPress site, and the supporting MySQL Database. You can see these in the “prod” folder below:

tree -L 3
.
├── README.md
├── compose.yml
├── copysource.sh
├── dockerfile-cp
├── dockerfile-mysql
├── dockerfile-wp
├── env.prod
├── env.test
├── mysql-init-files
├── prod
│   ├── mysql-init-files
│   │   └── prodwordpress.sql
│   └── wp-content
│   ├── cache
│   ├── index.php
│   ├── plugins
│   ├── themes
│   ├── upgrade
│   └── uploads
├── run
│   └── secrets
│   ├── db_password.txt
│   └── db_root_password.txt
├── test
│   ├── mysql-init-files
│   │   └── testwordpress.sql
│   └── wp-content
│   ├── cache
│   ├── index.php
│   ├── plugins
│   ├── themes
│   ├── upgrade
│   └── uploads
└── uploads.ini

20 directories, 15 files

However, I also need a set of ‘test’ data I can use if / when I need to upgrade either the MySQL or WordPress versions – you can see above there is also a ‘test’ folder with assets for both WordPress and MySQL therein. Certainly I don’t want to blindly deploy my production site with new versions of either without running through some basic testing to make sure neither a new version of WordPress or MySQL breaks anything – so I would prefer to do this with some test data.

To do this, I simply downloaded a pristine image of WordPress and MySQL from Docker Hub, and deployed a new ‘dummy’ blog with a couple images and posts that I can use for testing purposes. I was able to use the following command to export a copy of the MySQL database from the MySQL container as follows:

docker exec clean_wp-db-1 /usr/bin/mysqldump -u(user) -p(password) wordpress > wordpress.sql

Then I just used Docker Desktop to grab a copy of the “wp-content” folder from the WordPress container:

So both of those are now available in my repository, under the ‘test’ folder.

To be sure that my sample data actually populates a new, ‘test’ blog, I simply repeated the steps from How do I ‘containerize’ something, part 4: Docker and MySQL and How do I ‘containerize’ something, part 5: Docker and WordPress with the test / sample data, and sure enough, test blog!

So I am ready – I have:

  • database and files for my ‘production’ blog
  • database and files for my ‘test’ blog
  • working Dockerfile for WordPress
  • working Dockerfile for MySQL
  • working Compose file to bring them both up.

Tune in next time to see how to tie it all together!