1

I'm using a variant of the answer provided to this question: How to deal with persistent storage (e.g. databases) in docker. In particular, I'm running into problems with the backup/restore procedure. Here's the story...

I created a simple image to use as a container. The Dockerfile looks like this:

FROM busybox

VOLUME /var/lib/mysql

CMD /bin/sh

I created a container from this image with the following commands:

docker build -t myimages/datastore .

docker run --name mysql_data myimages/datastore true

Then I built the tutum/mariadb image and created a container:

docker run -d -p 3306:3306 --volumes-from mysql_data tutum/mariadb

Everything works fine. I can connect to the database using the mysql client and perform database operations. Specifically, I did this: create database testdb; and create table testtbl select 1 as 'id', 'hello' as 'word';.

Next, I attempted to back up my container. Following the answer to the question above (with a few modifications), I did this:

docker run --rm --volumes-from mysql_data -v $(pwd):/backup busybox \
    tar cvf /backup/backup.tar /var/lib/mysql

And voila! I had a backup.tar file in my backup folder on the host.

So, as a final step, I attempted to restore the backup with the following series of commands:

docker run --name mysql_data2 myimages/datastore true

docker run --rm --volumes-from mysql_data2 -v $(pwd):/backup busybox \
    tar xvf /backup/backup.tar -C /var/lib/mysql/

And I created a new MariaDB container which imported volumes from the new data container:

docker run -d -p 3308:3306 --volumes-from mysql_data2 tutum/mariadb

The new database container started up just fine, I connected to it with the mysql client, and checked the database. Here's where the problem arose: instead of having a testdb database (as created above), I have a var database; and instead of having a testtbl table inside the new database, there are no tables.

Can anyone see what I'm doing wrong? Thanks!

Community
  • 1
  • 1
Kryten
  • 15,230
  • 6
  • 45
  • 68

1 Answers1

2

It appears that proceeding this way (by copying the database files out of the container) simply will not work, because of the way MySQL stores data. Specifically, InnoDB files cannot just be copied - this documentation states that

table file copying methods do not work if your database contains InnoDB tables ... because InnoDB does not necessarily store table contents in database directories. Also, even if the server is not actively updating data, InnoDB may still have modified data cached in memory and not flushed to disk.

So the short answer to this question is "it can't be done this way". The long answer is to use mysqldump or a similar tool to do this.

Kryten
  • 15,230
  • 6
  • 45
  • 68