Docker Compose - 如何在一个mysql容器中引用多个模式 [英] Docker Compose - How reference many schemas in one mysql container

查看:2185
本文介绍了Docker Compose - 如何在一个mysql容器中引用多个模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将两个模式用于一个mysql容器。我有两个连接到两个不同模式的飞行服务。 Docker Compose的.yml文件如下所示:

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'

但是当我运行命令sudo docker-撰写终端显示此消息:

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

错误:撰写文件'./docker-compose.yml'无效,因为:
服务。 mysqldb.environment.MYSQL_DATABASE包含[mialquiler_post],这是一个无效的类型,它应该是一个字符串,数字或一个零

I traid而不指定MYSQL_DATABASE属性,但它没有起作用。

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

有什么办法吗?

推荐答案

MYSQL_DATABASE 变量允许创建单个数据库,如果指定,则将数据库授予的权限授予 MYSQL_USER

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.

如果需要创建多个数据库,您可以需要运行一些自定义SQL,因为flyway无法为您创建数据库。 飞行测试资源包括一个mysql示例

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.

这篇关于Docker Compose - 如何在一个mysql容器中引用多个模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆