Official Docker documentation provides a great overview on how to backup, restore, or migrate data volumes. For my problem, in particular, I did the following:
Run a throw-away Docker container that runs Ubuntu, shares volumes with currently running MySQL container, and backs up database data in local machine (as described in the overview):
docker run --rm --volumes-from some-mysql -v /path/to/local/directory:backup ubuntu:15.10 tar cvf /backup/mysql.tar /var/lib/mysql
(The official MySQL Docker image uses /var/lib/mysql
for storing data.)
The previous step will result in creation of /path/to/directory/mysql.tar
in the Docker host. This can now be extracted like:
tar -xvf mysql.tar
(Assuming cd /path/to/directory
). The resulting directory (/var/lib/mysql
) can now be used as shared volume with same instance, or any other instance of containerized MySQL.