简体   繁体   中英

Docker Compose - How reference many schemas in one mysql container

I'm trying to use two schemas into one mysql container. I have two flyway services that connect to two different schemas. The .yml file of Docker Compose looks like:

version: '2'

services:

mysqldb:
image: mysql:5.6.26
environment:
  MYSQL_USER: user
  MYSQL_PASSWORD: password
  MYSQL_ROOT_PASSWORD: password
  MYSQL_DATABASE:
  - my
  - my_post
ports:
  - "3306:3306"

 flyway-service1-i:
image: mik/flyway-service
volumes:
 - "../resources/db/migration:/migrations/ro"
depends_on:
 - mysqldb
links:
 - mysqldb
command: migrate -url=jdbc:mysql://mysqldb:3306/mi -user=user -password=password -baselineOnMigrate=true -locations='filesystem:/migrations'

flyway-service2-i:
image: mialk/flyway-post-service
volumes:
 - "../../../service2/src/main/resources/db/migration:/migrations/ro"
depends_on:
 - mysqldb
links:
 - mysqldb
command: migrate -url=jdbc:mysql://mysqldb:3306/mi_post -user=user -password=password -baselineOnMigrate=true -locations='filesystem:/migrations'

But when I run the command sudo docker-compose up the terminal show this message:

ERROR: The Compose file './docker-compose.yml' is invalid because: services.mysqldb.environment.MYSQL_DATABASE contains ["mialquiler", "mialquiler_post"], which is an invalid type, it should be a string, number, or a null

I traid without specifying MYSQL_DATABASE property, but it didn't work.

Is there any way to do that?

The MYSQL_DATABASE variable allows a single database to be created, and permissions granted on the database to the MYSQL_USER if specified.

You can use a single database to house multiple schema's.

If you need to create multiple databases you may need to run some custom SQL as flyway can't do database creation for you. The flyway test resources include a mysql example .

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