2

I am planning on self-hosting my wordpress on server using docker.

When using the official docker image with wordpress, how should I be handling my backups?

I will need to make sure my database has a volume where I can then backup the mysql database.

What about the filesystem to make sure my attachments are backed up?

Anything else to consider?

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.