How to Backup WordPress Data in Docker

When deploying WordPress using Docker, your website typically runs in separate containers — one for WordPress (source code) and another for the database (MySQL or MariaDB). Backing up WordPress data requires preserving two critical components:

  • WordPress source files: Includes themes, plugins, uploaded media, configuration files, etc.
  • Database: Stores all posts, pages, user accounts, and content.

Requirements

  • Docker/Docker Desktop must be running to execute Docker commands.
  • User must have write and execute permissions.
  • There must be sufficient free disk space to store backup files.
  • You need to know the correct volume/container/db_user (explained in the steps below).

Note: This guide uses <user_name> as a placeholder in commands. It represents the currently logged-in user. If you’re unsure what your username is, run whoami or $env:USERNAME (on Windows) in the terminal/PowerShell.

Docker Desktop on Windows or Linux has a nice, easy-to-use interface — but it’s a bit of a shame that it doesn’t include built-in backup or export features. No problem though! There are still plenty of ways to get the job done, and the steps below will walk you through everything clearly and simply.

Backing Up WordPress Source Files

If you’re using a volume to store source files, as in a docker-compose.yml configuration:

volumes:
  wordpress_data:

Open your docker-compose.yml to verify this setup. If it’s correct, you can compress the volume content using the steps below.

Backup on Linux/macOS

Backup Docker volume named wordpress_data into the ~/backups directory.

Step 1: Create a backup directory

mkdir -p ~/backups

Step 2: Run the backup command

docker run --rm -v wordpress_data:/data -v ~/backups:/backup alpine tar czf /backup/wordpress_files_backup.tar.gz -C /data .

✔️ Result: The backup file will be located at:
~/backups/wordpress_files_backup.tar.gz
Equivalent to: /home/your_user/backups/... (Linux) or /Users/your_user/backups/... (macOS)

Backup on Windows (CMD or PowerShell)

Backup Docker volume named wordpress_data into C:Users<user_name>backups.

Step 1: Create the backup folder

Search for PowerShell and run:

mkdir C:Users<user_name>backups

Step 2: Run the backup command

docker run --rm -v wordpress_data:/data -v C:Users<user_name>backups:/backup alpine tar czf /backup/wordpress_files_backup.tar.gz -C /data .

✔️ Result: The backup file will be located at:
C:Users<user_name>backupswordpress_files_backup.tar.gz

Alternative Option: You can also use the plugin “All-in-One WP Migration and Backup”, which is quite useful. It creates a .press file. To restore, simply install a fresh WordPress site and import this file.

Backing Up the Database (MySQL/MariaDB)

The database contains all website content, settings, and user data. You can back it up using the mysqldump command.

Step 1: Identify database credentials

In a Docker-based WordPress setup, your docker-compose.yml file will include these three essential variables:

  • WORDPRESS_DB_USER
  • WORDPRESS_DB_PASSWORD
  • WORDPRESS_DB_NAME

Make sure you know their values.

Step 2: Run the mysqldump command

Now use mysqldump with the appropriate user, password, and database name as identified above.

Linux/macOS:

mkdir -p ~/backups && docker exec wordpress_db_1 sh -c 'exec mysqldump -u wpuser -pwppass wpdb' > /home/<user_name>/backups/wordpress_db_backup.sql

✔️ Result: The backup file will be saved at:
/home/<user_name>/backups/wordpress_db_backup.sql

Windows (PowerShell):

mkdir C:Users<user_name>backups; docker exec wordpress_db_1 sh -c "exec mysqldump -u wpuser -pwppass wpdb" > C:Users<user_name>backupswordpress_db_backup.sql

✔️ Result: The file will be saved at:
C:Users<user_name>backupswordpress_db_backup.sql

With just a few simple commands, you can fully back up both the WordPress source files and database within Docker — giving you peace of mind and the ability to restore your WordPress site anytime.

Write a comment