Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL容器无法在Docker Compose中运行初始化脚本_Mysql_Docker_Docker Compose - Fatal编程技术网

MySQL容器无法在Docker Compose中运行初始化脚本

MySQL容器无法在Docker Compose中运行初始化脚本,mysql,docker,docker-compose,Mysql,Docker,Docker Compose,让我的MySQL容器从Docker Compose运行一些初始化脚本(创建一些数据库)时遇到问题。根据Docker Hub上的文档,我将.sql文件装载到/Docker entrypoint initdb.d中,但没有任何效果 我的撰写文件如下: version: '2' services: database: image: mysql ports: - "3307:3306" environment: MYSQL_ROOT_PASSWORD

让我的MySQL容器从Docker Compose运行一些初始化脚本(创建一些数据库)时遇到问题。根据Docker Hub上的文档,我将
.sql
文件装载到
/Docker entrypoint initdb.d
中,但没有任何效果

我的撰写文件如下:

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
/scripts/db
的内容只是一个文件
init databases.sql

CREATE DATABASE myservice;
一旦启动,MySQL将运行,但不会创建数据库。服务容器还成功链接到MySQL容器。攻击MySQL容器;初始化脚本已成功装入正确的位置

有人能看到一些明显的问题吗


来自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)

检查这是否是docker撰写问题(如重定向到的问题)

我认为这个错误与构建无关,很可能与卷有关。
Compose会保留卷,这样您就不会丢失数据(在下一版本中会更好地记录这一点)

要删除这些卷,请运行
docker compose rm-vf
。下次docker编写时,应该从新的空卷开始

根据,还要检查这是否不是同步问题:

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


看看这是否是权限问题。容器上sql文件的所有者id是什么?@warmoverflow-看起来不像,目前拥有权限-rwxrwx由员工拥有。不确定它是1,日志对我来说似乎正常(添加到问题中)。我也不认为这是一个同步问题,因为有三个原因。1,当我在数据库开始接受连接后连接到数据库时,数据库仍然没有创建。2,当我添加MYSQL_DATABASE env变量时,它仍然不会创建数据库。3,当我在同一个坐骑中添加一个ECHO.SH文件(图像也说它也会运行)时,用一个简单的回音语句,它不运行。@ NICOHYYSAMEN OK,我添加了额外的线索供您考虑。是的,解决了启动问题,谢谢!现在我正在处理同步问题…删除卷。不需要引用密码。@nicohuisamen好极了!我已经相应地整理了答案。