0

I want mysql read/write data to my RBD image. I use rbd-docker-plugin to mount RBD into docker pull from https://hub.docker.com/_/mysql/

First I try

docker run -it --volume-driver=rbd --volume foo:/mnt/foo ceph/base bash

and I touch "aa" file inside /mnt/foo in docker then I stop docker and when I mount foo into another docker "aa" file still exist


Then I add my code into this Docker file

RUN mkdir -p /mnt/foo/mysql
RUN sed -i -e 's/\/var\/lib\/mysql/\/mnt\/foo\/mysql/g' /etc/mysql/my.cnf
VOLUME /mnt/foo/mysql

and build, run docker from this new Dockerfile

docker run -it --volume-driver=rbd --volume storage2/foo:/mnt/foo -e MYSQL_ROOT_PASSWORD=password [image_id]

when I exec container I can use mysql and I see data of mysql (and "aa" file) in /mnt/foo/mysql, But when I stop docker and mount foo into another docker I can't see anything about mysql (but I still see "aa" file)


Finally I try

docker run --name some-mysql --volume-driver=rbd --volume foo:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql

but it error

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist

SilverIce
  • 75
  • 1
  • 13

1 Answers1

2

The error message says that there are no mysql files for mysql to read.

The problem is that you are mounting the partition after the installation of mysql so the partition will be empty.

Solution: start mysql with --initialize or --initialize-insecure

http://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html

atsa
  • 195
  • 7