MySQL容器未能在Docker Compose中运行初始化脚本 [英] MySQL container failing to run initialisation scripts in Docker Compose

查看:1105
本文介绍了MySQL容器未能在Docker Compose中运行初始化脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题让我的MySQL容器从Docker Compose运行一些初始化脚本(创建一些数据库)。根据Docker Hub的文档,我在 /docker-entrypoint-initdb.d 中挂载 .sql 无法使用。



我的撰写文件如下:

 版本:'2'

服务:
数据库:
图像:mysql
端口:
- 3307:3306
环境:
MYSQL_ROOT_PASSWORD:root
卷:
- ./scripts/db:/docker-entrypoint-initdb.d

myservice:
image:company / myservice
曝光:
- 10001
depends_on:
- 数据库
链接:
- 数据库
环境:
SERVICE_PORT :10001
DATABASE_URL:jdbc:mysql:// database:3306 / myservice?autoReconnect = true& useSSL = false& characterEncoding = UTF-8

./ scripts / db 的内容只是一个文件 init-databases.sql

  CREATE DATABASE myservice; 

一旦启动,MySQL正在运行,但数据库未创建。服务容器也成功地链接到MySQL容器。砸入MySQL容器初始化脚本成功安装在正确的位置。



任何人都可以在这里看到一些明显的问题?






LOGS FROM compose

  database_1 | 2016-04-01T05:35:55.020279Z 0 [注意] mysqld(mysqld 5.7.11)从进程1开始... 
database_1 | 2016-04-01T05:35:55.023277Z 0 [注意] InnoDB:PUNCH HOLE支持可用
database_1 | 2016-04-01T05:35:55.023305Z 0 [注意] InnoDB:Mutexes和rw_locks使用GCC原子内置函数
database_1 | 2016-04-01T05:35:55.023316Z 0 [注意] InnoDB:使用事件互斥体
database_1 | 2016-04-01T05:35:55.023324Z 0 [注意] InnoDB:GCC内置__atomic_thread_fence()用于记忆障碍
database_1 | 2016-04-01T05:35:55.023332Z 0 [注意] InnoDB:压缩表使用zlib 1.2.8
database_1 | 2016-04-01T05:35:55.023344Z 0 [注意] InnoDB:使用Linux本机AIO
database_1 | 2016-04-01T05:35:55.023491Z 0 [注意] InnoDB:游泳池数量:1
database_1 | 2016-04-01T05:35:55.023566Z 0 [注意] InnoDB:使用CPU crc32指令
database_1 | 2016-04-01T05:35:55.028689Z 0 [注意] InnoDB:初始化缓冲池,总大小= 128M,实例= 1,块大小= 128M
database_1 | 2016-04-01T05:35:55.041026Z 0 [注意] InnoDB:完成缓冲池的初始化
database_1 | 2016-04-01T05:35:55.047324Z 0 [注意] InnoDB:如果mysqld执行用户被授权,页面清除线程优先级可以更改。请参阅setpriority()的手册页。
database_1 | 2016-04-01T05:35:55.061537Z 0 [注意] InnoDB:最受支持的文件格式是Barracuda。
database_1 | 2016-04-01T05:35:55.076895Z 0 [注意] InnoDB:为临时表创建共享表空间
database_1 | 2016-04-01T05:35:55.076987Z 0 [注意] InnoDB:将文件'./ibtmp1'的大小设置为12 MB。物理上写完文件;请稍候...
database_1 | 2016-04-01T05:35:55.095683Z 0 [注意] InnoDB:文件'./ibtmp1'的大小现在是12 MB。
database_1 | 2016-04-01T05:35:55.096484Z 0 [注意] InnoDB:发现了96个重做回滚段。 96个重做回滚段有效。
database_1 | 2016-04-01T05:35:55.096540Z 0 [注意] InnoDB:32个非重做回滚段有效。
database_1 | 2016-04-01T05:35:55.096931Z 0 [注意] InnoDB:等待清除启动
database_1 | 2016-04-01T05:35:55.147986Z 0 [注意] InnoDB:5.7.11开始;日志序列号11992841
database_1 | 2016-04-01T05:35:55.148204Z 0 [注意]插件'FEDERATED'被禁用。
database_1 | 2016-04-01T05:35:55.149262Z 0 [注意]在数据目录中找到ca.pem,server-cert.pem和server-key.pem。尝试使用SSL支持。
database_1 | 2016-04-01T05:35:55.149443Z 0 [警告] CA证书ca.pem是自签名的。
database_1 | 2016-04-01T05:35:55.150272Z 0 [注意] InnoDB:从/ var / lib / mysql / ib_buffer_pool加载缓冲池
database_1 | 2016-04-01T05:35:55.151068Z 0 [注意] InnoDB:缓冲池加载完成160401 5:35:55
database_1 | 2016-04-01T05:35:55.152775Z 0 [注意]服务器主机名(bind-address):'*';端口:3306
database_1 | 2016-04-01T05:35:55.154441Z 0 [注意] IPv6可用。
database_1 | 2016-04-01T05:35:55.154553Z 0 [注意] - '::'解析为'::';
database_1 | 2016-04-01T05:35:55.154571Z 0 [注意]在IP上创建的服务器套接字:'::'。
database_1 | 2016-04-01T05:35:55.156680Z 0 [警告]'-skip-name-resolve模式中忽略'db'条目'sys mysql.sys@localhost'。
database_1 | 2016-04-01T05:35:55.156738Z 0 [ - 在-skip-name-resolve模式下忽略'proxies_priv'条目'@ root @ localhost'。
database_1 | 2016-04-01T05:35:55.158280Z 0 [ - ] -skip-name-resolve模式中忽略'tables_priv'条目'sys_config mysql.sys@localhost'。
database_1 | 2016-04-01T05:35:55.165273Z 0 [注意]事件计划程序:加载0事件
database_1 | 2016-04-01T05:35:55.173462Z 0 [注意] mysqld:准备连接。
database_1 |版本:'5.7.11'socket:'/var/run/mysqld/mysqld.sock'port:3306 MySQL社区服务器(GPL)


解决方案

检查这是否是docker-compose问题(如问题115 重定向到问题2266


我不认为错误与构建有关,这主要是可能的。

撰写保留卷,以便您不会丢失数据(这将在下一版本中更好地记录下来)。



要删除那些卷,运行 docker-compose rm -vf 。下一次你停泊的时候,应该从新的空卷开始。


根据 hub.docker.com/mysql ,同时检查这是否不是同步问题:


如果容器启动时没有初始化数据库,则将创建一个默认数据库。虽然这是预期的行为,这意味着它将不会接受传入的连接,直到这样的初始化完成。 使用自动化工具时,可能会导致问题,如docker-compose,同时启动多个容器。



I am having issues getting my MySQL container to run some initialisation scripts (creating some databases) from Docker Compose. As per the documentation on Docker Hub, I mount the .sql files in /docker-entrypoint-initdb.d but to no avail.

My compose files is as follows:

version: '2'

services:
  database:
    image: mysql
    ports:
      - "3307:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - ./scripts/db:/docker-entrypoint-initdb.d

  myservice:
    image: company/myservice
    expose:
      - "10001"
    depends_on:
      - database
    links:
      - database
    environment:
      SERVICE_PORT: 10001
      DATABASE_URL: jdbc:mysql://database:3306/myservice?autoReconnect=true&useSSL=false&characterEncoding=UTF-8

And the contents of ./scripts/db is just 1 file init-databases.sql:

CREATE DATABASE myservice;

Once started up, MySQL is running, but the database is not created. The service container also successfully links to the MySQL container. Bashing into the MySQL container; the init scripts are successfully mounted in the correct location.

Can anyone see some obvious issues here?


LOGS FROM compose

database_1   | 2016-04-01T05:35:55.020279Z 0 [Note] mysqld (mysqld 5.7.11) starting as process 1 ...
database_1   | 2016-04-01T05:35:55.023277Z 0 [Note] InnoDB: PUNCH HOLE support available
database_1   | 2016-04-01T05:35:55.023305Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
database_1   | 2016-04-01T05:35:55.023316Z 0 [Note] InnoDB: Uses event mutexes
database_1   | 2016-04-01T05:35:55.023324Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
database_1   | 2016-04-01T05:35:55.023332Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
database_1   | 2016-04-01T05:35:55.023344Z 0 [Note] InnoDB: Using Linux native AIO
database_1   | 2016-04-01T05:35:55.023491Z 0 [Note] InnoDB: Number of pools: 1
database_1   | 2016-04-01T05:35:55.023566Z 0 [Note] InnoDB: Using CPU crc32 instructions
database_1   | 2016-04-01T05:35:55.028689Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
database_1   | 2016-04-01T05:35:55.041026Z 0 [Note] InnoDB: Completed initialization of buffer pool
database_1   | 2016-04-01T05:35:55.047324Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
database_1   | 2016-04-01T05:35:55.061537Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
database_1   | 2016-04-01T05:35:55.076895Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
database_1   | 2016-04-01T05:35:55.076987Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
database_1   | 2016-04-01T05:35:55.095683Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
database_1   | 2016-04-01T05:35:55.096484Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
database_1   | 2016-04-01T05:35:55.096540Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
database_1   | 2016-04-01T05:35:55.096931Z 0 [Note] InnoDB: Waiting for purge to start
database_1   | 2016-04-01T05:35:55.147986Z 0 [Note] InnoDB: 5.7.11 started; log sequence number 11992841
database_1   | 2016-04-01T05:35:55.148204Z 0 [Note] Plugin 'FEDERATED' is disabled.
database_1   | 2016-04-01T05:35:55.149262Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
database_1   | 2016-04-01T05:35:55.149443Z 0 [Warning] CA certificate ca.pem is self signed.
database_1   | 2016-04-01T05:35:55.150272Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
database_1   | 2016-04-01T05:35:55.151068Z 0 [Note] InnoDB: Buffer pool(s) load completed at 160401  5:35:55
database_1   | 2016-04-01T05:35:55.152775Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
database_1   | 2016-04-01T05:35:55.154441Z 0 [Note] IPv6 is available.
database_1   | 2016-04-01T05:35:55.154553Z 0 [Note]   - '::' resolves to '::';
database_1   | 2016-04-01T05:35:55.154571Z 0 [Note] Server socket created on IP: '::'.
database_1   | 2016-04-01T05:35:55.156680Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
database_1   | 2016-04-01T05:35:55.156738Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
database_1   | 2016-04-01T05:35:55.158280Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
database_1   | 2016-04-01T05:35:55.165273Z 0 [Note] Event Scheduler: Loaded 0 events
database_1   | 2016-04-01T05:35:55.173462Z 0 [Note] mysqld: ready for connections.
database_1   | Version: '5.7.11'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

解决方案

Check if this is a docker-compose issue (like issue 115 which redirected to issue 2266)

I don't think the error is related to build, it's mostly likely volumes.
Compose preserves volumes so that you don't lose data (this will be better documented in the next release).

To remove those volumes run docker-compose rm -vf. The next time you docker-compose up it should start with fresh empty volumes.

According to hub.docker.com/mysql, check also if this is not a synchronization issue:

If there is no database initialized when the container starts, then a default database will be created. While this is the expected behavior, this means that it will not accept incoming connections until such initialization completes. This may cause issues when using automation tools, such as docker-compose, which start several containers simultaneously.

这篇关于MySQL容器未能在Docker Compose中运行初始化脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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