My Old WordPress in docker

Photo by chuttersnap on Unsplash

This blog was offline for about 7 years. Before this, it was a self-hosted WordPress installation for which I had (somewhat buried in my backups) an up-to-date dump of the MySQL database. Once I managed to find the backup that survived to live in 5 houses, moving between 3 countries, and my messiness, I didn’t have anywhere to load it; the server hosting the blog was not there anymore. I was planning on using a one-click install in DigitalOcean, since I didn’t want to spend time setting up Apache, PHP, and all required things to run WordPress. I was not sure if I could plainly load this old database into a more modern WordPress, so I decided to experiment a bit running things in docker first.

The first step was to load the database into a container; I had a file called fclaude_blog2.sql containing the old dump. I loaded the database (the default authentication plugin is because the default authentication of the latest version of MySQL is not supported, you can also get around by spinning an older version fo MySQL):

docker run --name wp-mysql -p 3306:3306  \
  -e MYSQL_ROOT_PASSWORD=nopass -d mysql \

The default authentication plugin setting is because the default authentication of the latest version of MySQL is not supported. You can also get around by spinning an older version fo MySQL. Once the database was running, I just pushed the dump into it:

exec -i wp-mysql mysql -uroot -pnopass 
# (typed 'create database fclaude_blog' and then closed the shell)

exec -i wp-mysql mysql -uroot -pnopass \
  fclaude_blog < Documents/fclaude_blog2.sql

Now I could see my data, but I wanted the XML export to load into my new WordPress, and to do so, I needed to run WordPress and connect it to this database.

docker run -ti --name wp -p 8080:80 -e WORDPRESS_DB_USER=root \
  -e WORDPRESS_DB_NAME=fclaude_blog --link wp-mysql -d wordpress

Note that this is the settings of the MySQL we just set up, adding the –link option, so this container sees the container running the database.

The most amazing part, at least to me, is that as soon as I accessed http://localhost:8080/wp-admin/ WordPress told me the database was in an old format and offered to upgrade it. It worked perfectly, so now I was ready to log into my blog, and get the file I needed! Except that I did not remember the password anymore!

Following the WordPress documentation, I found that the password in the database was an md5. Per their recommendation, you could write the password in a text file, run the following command, and then delete the file (hopefully).

tr -d '\r\n' < pass.txt | md5sum | tr -d ' -'

I went into the MySQL container and updated the users’ table, setting the password field to the result from that command. And that was it! Then I could export my data and load it into this blog.

After this, I just did:

docker kill wp wp-mysql
docker rm wp wp-mysql

And now, my machine is also not full of stuff I had no intention of permanently installing locally in the first place.

Through all this experiment, the part I’m most surprised by is how WordPress handled the old database. I have no idea what changed, but still, now my database was up to date and working. Kudos to WordPress for this!

This entry was posted in Docker, Wordpress. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.