It Belongs in a Museum

How to Spin Up an Old WordPress Backup in Docker and Migrate Your Posts and Media

I was digging through an old folder on my drive the other day and found a full server backup of my old tech blog. It had been sitting there for years, complete with a public_html folder and a compressed MySQL dump. I wanted to pull those old posts into my current WordPress site without overwriting anything, and I definitely did not want to risk breaking a live server just to read a handful of articles from 2015.

Spinning up the old site in an isolated Docker container solved the whole problem. Once it was running on my TrueNAS box, I could log in, export the posts and media cleanly, and tear the container right back down.

Prerequisites

Before you start, make sure you have these ready:

  • A host running Docker and Docker Compose (I used my TrueNAS server).
  • Your old WordPress backup files (specifically the wp-content folder and the .sql or .sql.gz database dump).
  • A destination WordPress site where you want to import the content.

Spinning Up the Old Site in Docker

The biggest catch with restoring an older WordPress backup is version drift. My backup was running WordPress 5.1, which will immediately crash with fatal errors if you drop it onto a modern PHP 8.x container. Instead of using the latest tag, pin your container to a matching PHP version like wordpress:5.1-php7.3-apache and pair it with mariadb:10.6.

Mount only your backed-up wp-content folder instead of the entire public_html directory. That lets the container generate a fresh wp-config.php using your Docker database credentials while keeping your themes, plugins, and uploaded images intact. Create a docker-compose.yml file in your backup directory with your own database credentials and placeholder URL:

services:
  db:
    image: mariadb:10.6
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: old_wp
      MYSQL_USER: wp_user
      MYSQL_PASSWORD: wp_password
    volumes:
      - db_data:/var/lib/mysql
      - ./db_backup:/docker-entrypoint-initdb.d:ro

  wordpress:
    image: wordpress:5.1-php7.3-apache
    depends_on:
      - db
    restart: unless-stopped
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_NAME: old_wp
      WORDPRESS_DB_USER: wp_user
      WORDPRESS_DB_PASSWORD: wp_password
      WORDPRESS_TABLE_PREFIX: wp_
      WORDPRESS_CONFIG_EXTRA: |
        define('WP_HOME', 'http://<your-server-ip>:8080');
        define('WP_SITEURL', 'http://<your-server-ip>:8080');
    volumes:
      - ./public_html/wp-content:/var/www/html/wp-content

volumes:
  db_data:
Code language: YAML (yaml)

Make sure the $table_prefix value matches the prefix inside your .sql dump, otherwise WordPress will think it is a brand-new install and show you the setup wizard. Once the file is saved, start the stack from the same directory:

docker compose up -d
Code language: Bash (bash)

MariaDB automatically imports .sql and .sql.gz files placed in /docker-entrypoint-initdb.d on the first boot, so your database comes up populated without any extra commands. Adding WP_HOME and WP_SITEURL in WORDPRESS_CONFIG_EXTRA also stops WordPress from redirecting you back to your old domain when you try to load the dashboard.

Resetting a Forgotten Admin Password

If your backup is old enough that you no longer remember the password, or you no longer own the email address tied to the account, you can reset both straight from the database container. WordPress accepts an MD5 hash in the user_pass column and automatically upgrades it to its native secure hash the first time you log in.

  1. List the users in your database to find your account ID and user_login:
docker exec -it <db-container-name> mysql -u wp_user -pwp_password old_wp -e "SELECT ID, user_login, user_email FROM wp_users;"
Code language: Bash (bash)
  1. Update the password (and email address, if you want) for that user ID:
docker exec -it <db-container-name> mysql -u wp_user -pwp_password old_wp -e "UPDATE wp_users SET user_pass = MD5('NewPassword123!') WHERE ID = 1;"
Code language: Bash (bash)

Now you can log into http://<your-server-ip>:8080/wp-admin with your old username and the new password.

Exporting Posts and Media Without Losing Your Mind

When you export content using Tools > Export, WordPress gives you a WXR .xml file. That file does not actually contain your images; it only contains links pointing back to where those images live. When you run Tools > Import > WordPress on your new site, the destination server tries to download each image over the network.

That is where a few sneaky gotchas can trip you up:

  1. Private IPs and non-standard ports get blocked: WordPress includes built-in Server-Side Request Forgery (SSRF) protection (wp_http_validate_url()) that blocks outbound importer requests to private LAN IPs and any port other than 80, 443, or 8080. If your temporary container is not running on 80, 443, or 8080, or is only reachable on a private LAN IP, the media import will fail silently.
  2. Enable debug output when media fails: By default, the importer hides the real reason an image failed. Temporarily add define( 'IMPORT_DEBUG', true ); to wp-config.php on your destination site and run the import again so you can see the actual error.
  3. Make sure the attachment box is checked: In my case, turning on IMPORT_DEBUG printed Fetching attachments is not enabled for every single image. On the Assign Authors screen right before clicking Submit, you have to check Download and import file attachments under Import Attachments.

To keep your network locked down while the new site pulls the images, avoid poking permanent holes in your firewall. A temporary reverse proxy or Cloudflare Tunnel pointing at your container gives you a clean https:// URL on port 443 that you can shut right back down as soon as the import finishes. Since the .xml export is plain text, you can do a quick find-and-replace on the old URL inside the .xml file before uploading it.

Cleaning Up Imported Drafts

If you do not want a pile of ten-year-old posts showing up on your front page right away, you will probably switch them to Draft in Posts > All Posts. One quick heads-up: WordPress only shows 20 items per page by default. If you select all, use Bulk Actions > Edit, and forget to check page two, the rest of your imported posts will still be sitting live on your homepage. Open Screen Options in the top right and bump up Number of items per page so you can bulk-edit all of them in one pass. Yes, I’m mentioned this because I got burned by it. Hello? McFly? Think, McFly!

Once your posts and media are safely on the new site, remove IMPORT_DEBUG from wp-config.php, close any temporary tunnel or DNS record you created, and run docker compose down -v on the temporary stack. Running the old backup in Docker keeps your live site clean and gives you a safe sandbox to pull out what you need without leaving any mess behind.

Published on

by

Nick

Leave a Comment