【问题标题】:How to set up docker-compose to initialize MySQL database on Windows 10?如何设置 docker-compose 在 Windows 10 上初始化 MySQL 数据库?
【发布时间】:2018-04-21 18:21:00
【问题描述】:

我正在尝试使用具有此配置的 docker-compose 创建 MySQL 数据库(在 Docker 容器上,在 Windows 10 主机上使用 docker 工具箱):

docker-compose.yml

version: '2'
services:
  db:
    container_name: test
    restart: unless-stopped
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: 'password'
      MYSQL_DATABASE: 'mydb'
    ports: 
      - 6612:3306
    volumes:
      - ./db:/var/lib/mysql

我在一个仅包含docker-compose.yml 的文件夹中运行它并获得以下输出。

$ docker-compose up

Recreating test ... done
Attaching to test
test  | Initializing database
test  | 2018-04-21T17:31:30.722810Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
test  | 2018-04-21T17:31:30.727269Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
test  | 2018-04-21T17:31:30.727618Z 0 [ERROR] Aborting
test  |
test  | Initializing database
test  | 2018-04-21T17:31:30.722810Z 0 [Warning] TIMESTAMP with implicit 
      .
      .
      .

它似乎在抱怨文件存在,但是当文件夹为空时怎么可能呢?

我第二次在同一个空文件中运行同一个文件(docker-compose.yml 除外)我得到:

Starting test ... done
Attaching to test
test  | Initializing database
test  | 2018-04-21T17:36:12.716214Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
test  | 2018-04-21T17:36:12.726611Z 0 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
test  | 2018-04-21T17:36:13.466867Z 0 [ERROR] InnoDB: Operating system error number 22 in a file operation.
test  | 2018-04-21T17:36:13.467174Z 0 [ERROR] InnoDB: Error number 22 means 'Invalid argument'
test  | 2018-04-21T17:36:13.467475Z 0 [ERROR] InnoDB: File ./ib_logfile101: 'aio write' returned OS error 122. Cannot continue operation
test  | 2018-04-21T17:36:13.467649Z 0 [ERROR] InnoDB: Cannot continue operation.
test exited with code 1

这次它在我的密码中创建了一个 ./db 文件夹,其中包含一些文件:

  • ib_logfile1
  • ib_logfile101
  • ibdata1

但仅此而已,再次运行它,我们又回到了第一个输出。相同的 docker-compose.yml 在 Ubuntu 16.04 上运行顺利。谁能告诉我可能出了什么问题?

【问题讨论】:

    标签: mysql docker docker-compose


    【解决方案1】:

    似乎关键在这个输出行中:

    [ERROR] InnoDB: File ./ib_logfile101: 'aio write' returned OS error 122.
    

    显然启用 AIO 不适用于我的设置。我仍然不确定为什么,但这个修改后的 docker-compose.yml 对我有用:

    version: '2'
    services:
      db:
        container_name: test
        restart: unless-stopped
        image: mysql:5.7
        command: --innodb_use_native_aio=0
        environment:
          MYSQL_ROOT_PASSWORD: 'password'
          MYSQL_DATABASE: 'mydb'
        ports: 
          - 6612:3306
        volumes:
          - ./db:/var/lib/mysql
    

    感谢 AndrewD 的answer 发现这个问题仍然不确定到底是什么问题。虽然我怀疑 Docker Toolbox(相对于 Docker for Windows)可能与它有关。

    【讨论】:

    • 它对我不起作用,但我有错误File ./ibdata1: 'open' returned OS error 71.
    猜你喜欢
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    相关资源
    最近更新 更多