如何使用Docker for Windows创建MySQL数据库?

时间:2018-02-13 18:55:09

标签: docker-compose docker-for-windows

我正在使用Docker for Windows Version 17.12.0-ce-win47 (15139)和Hyper-V。

我正在尝试将现有架构恢复到docker容器中,但不断收到错误。

搬运工-compoer.yml:

version: '3'

services:
  mysql:
    image: mysql
    environment:
      MYSQL_USER: test
      MYSQL_PASSWORD: testtest
      MYSQL_RANDOM_ROOT_PASSWORD: 1
    volumes:
      - ./Schema/:/docker-entrypoint-initdb.d/

架构/ TEST.SQL:

CREATE DATABASE IF NOT EXISTS test;
USE test;

CREATE TABLE IF NOT EXISTS data (
    Id INT PRIMARY KEY AUTO_INCREMENT
);

当我跑步时:

docker-compose up

我收到此错误:

ERROR: for workspace_mysql_1  Cannot create container for service mysql: invalid volume specification: 'C:\Users\Kyle\Workspace\Schema:/docker-entrypoint-initdb.d/:rw'

ERROR: for mysql  Cannot create container for service mysql: invalid volume specification: 'C:\Users\Kyle\Workspace\Schema:/docker-entrypoint-initdb.d/:rw'
Encountered errors while bringing up the project.

我也在Docker for Mac上进行了测试,看起来效果很好。

1 个答案:

答案 0 :(得分:0)

您还需要在docker-compose.yml中指定卷名,与服务并行添加此

    volumes:
     ./Schema/: