Using docker with wordpress, how to handle backups correctly?

There is really only two things you need to back up. The database, and the site data. The database is all your users, posts, categories, tags, etc. The site data includes your themes, plugins, uploaded media, etc.

To backup the database, just dump the data with mysqldump.

mysqldump -u {username} -p{password} wordpress > database_dump.sql

If your host machine is shared by other users, you may not want to put the password in the command. If so, you can create a ~/.my.cnf file that has your password and skip those options.

[mysqldump]
user={username}
password={password}

See this post for more information.

If you also have dockerized your database, you should just be able to docker exec the command, when you redirect the output it will go to the host.


For the site content, you should have that mounted as a volume anyway. If you don’t, every time you restart you will lose your theme and uploads and anything else stored there.

I have mine configured like so (docker-compose)

volumes:
      - ./site_content/var/www/html:/var/www/html

You can just back up the entire directory. In theory you should only need the wp-content directory, but unless your site is massive, it shouldn’t really hurt to grab the entire thing just in case something goes really wrong.

I would also recommend backing up your docker-compose file, or your start script, however you launch the application.

So that should be three things. Site content, database, and docker configuration. That should do it.