Docker multiple MySQL containers with persistence

这一生的挚爱 提交于 2019-12-24 15:42:51

问题


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:

  1. How to implement data-only container properly for multiple MySQL containers?
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!