Docker: split mysql databases into different data volume containers?
I have the following Docker containers:
web container is linked to the
db container. All standard stuff.
For data persistence, I want to take the data volume container approach.
I want to be able to run several websites using these 2 containers as the main application containers (well, technically, the
web container runs the main user-facing application and the
db sits behind that).
Let’s say I have
siteC using databases
C respectively in mysql.
I would like to be able to partition these site’s database data into 3 different data volume containers (
dataC) for portability, and bring them together in a single deployment (one host running
dataC all linked appropriately) when needed.
Is there a way to partition the separate mysql databases into their own data volume containers for portability? AFAIK, mysql stores all of it’s database data in
/var/lib/mysql in some fashion that is not transparent in terms of the databases that mysql is storing.
For example, it would be nice if the different databases being stored in mysql were mapped to known directories – in this case,
/var/lib/mysql/C. This way, all I would have to do persist those directories and mount them in the
db container. I don’t think this is the case though.
One Solution collect form web for “Docker: split mysql databases into different data volume containers?”
Why not just run multiple instances of the db container? Mapping the dir’s as needed.
docker run -d -v /var/lib/mysql/A:/var/lib/mysql --name dbA my_docker/my_awesome_mysql docker run -d -v /var/lib/mysql/B:/var/lib/mysql --name dbB my_docker/my_awesome_mysql docker run -d -v /var/lib/mysql/C:/var/lib/mysql --name dbC my_docker/my_awesome_mysql
This would help if you ever needed to move dbA only to another host.