简体   繁体   中英

Docker multiple MySQL containers with persistence

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM