ItsmeITItsmeIT
  • Linux
    • Debian
    • Ubuntu
  • PC/Windows
Reading: How to Backup WordPress Data in Docker
Share
Notification Show More
Font ResizerAa
ItsmeITItsmeIT
Font ResizerAa
  • Categories
    • Linux
    • Debian
    • Ubuntu
    • PC/Windows
Have an existing account? Sign In
Follow US
© 2025 ItsmeIT. All rights reserved.

Home » Linux » How to Backup WordPress Data in Docker

How to Backup WordPress Data in Docker

avatar
By
Loibv
avatar
ByLoibv
The ItsmeIT team – delivering cutting-edge updates, tech trends, and insider knowledge from the world of technology.
Follow:
Last updated: July 25, 2025

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.

1. 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>\backups\wordpress_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.

2. 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>\backups\wordpress_db_backup.sql

✔️ Result: The file will be saved at:
C:\Users\<user_name>\backups\wordpress_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.

TAGGED:Docker
Share This Article
Facebook Reddit Telegram Threads
avatar
ByLoibv
Follow:
The ItsmeIT team – delivering cutting-edge updates, tech trends, and insider knowledge from the world of technology.
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

Most Popular

Install WordPress Using Docker on Windows 11
How to Install WordPress Using Docker on Windows 11
Docker Data Folder Structure on Windows
Docker Data Folder Structure on Windows (Volume, Image, Container)
What Is Docker?
What Is Docker? How It Works and Why You Should Use It
Install Docker Desktop on Windows 11
How to Install Docker Desktop on Windows 11
Install Docker on Linux
How to Install Docker on Linux (Ubuntu, Debian, RHEL, AlmaLinux)
ItsmeITItsmeIT
Follow US
© 2025 ItsmeIT. All Rights Reserved.
  • Privacy Policy
  • Terms of Service
Logo ItsmeIT logo
Welcome Back!

Sign in to your account

Continue with Google
Register   |Lost your password?