问题
I am trying to setup two MySQL containers and one data-only container for persisting MySQL data using Docker Compose.
Here is docker-compose.yml:
db1:
image: mysql
volumes_from:
- data
environment:
- MYSQL_ROOT_PASSWORD=password
db2:
image: mysql
volumes_from:
- data
environment:
- MYSQL_ROOT_PASSWORD=password
data:
image: mysql
volumes:
- /var/lib/mysql
entrypoint: /bin/echo
However, both mysql daemons have conflict, because they need a separate data directory:
[Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
[ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
Consequently, I have two questions:
- How to implement data-only container properly for multiple MySQL containers?
- How to implement data-only container for multiple MySQL containers as a cluster with Master-Master replication and load balancer?
回答1:
As far as I know, the MySQL daemon would request an exclusive lock on the data files. This lock would then prevent the second instance from spinning up, which might explain the error you're seeing.
Perhaps try doing a master slave rig where you have two different volumes, but the slave (db2) is tied to db1?
来源:https://stackoverflow.com/questions/34636261/docker-multiple-mysql-containers-with-persistence