terbooter
terbooter

Reputation: 399

Is it safe to export tarball of running docker container?

I am playing a couple of days with docker.io. It is awesome! Some simple containers already run in production servers.

At the moment I stuck in how to make container backup. Assume I have running complicated docker container with supervisor+apache+memcached+mysql inside under hi load (10k requests per second). Is it safe to make

docker export > backup.tar

Or I have to stop all processes inside container and only after that export container to tar file?

Upvotes: 1

Views: 1092

Answers (1)

mbarthelemy
mbarthelemy

Reputation: 12913

If by "safe" you mean "consistent", then the exported archive will be filesystem consistent.

The docker exportcommand, as any other classical backup method, won't solve the problem of being application consistent.

Apache and Memcached won't be an issue, since they don't need storage to maintain any kind of state.

But backuping Mysql this way will probably make your database restart in recovery mode, if you run a container from the image generated by docker export.

In particular, if backuped when having to perform write activity (insert, updates..), as with any other filesystem-level backup, you will loose a few transactions.

If you need your Mysql backuped datafiles to be 100% consistent and to reflect the exact state of your data, you have to either:

  • Stop Mysql before running docker export
  • Stop the whole container
  • Have something connecting to Mysql before running the export command, and run flush tables with read lock;. When the export completes, you'd have to run unlock tables;The backuped data files (generally under /var/lib/mysql) will be consistent.
  • Use the classical Mysql backup tools (mysqldump...)

Upvotes: 2

Related Questions