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!