Windows卷上的docker-compose无法正常工作

标签 docker-compose yaml docker-volume

在过去的一周中,我一直在与Docker一起玩,并且认为容器的想法非常有用,但是尽管过去三天我都读了我所有的内容,但是我无法使卷映射正常工作

get docker-compose to use my existing volume.

    Docker Version: 18.03.1-ce
    docker-compose version 1.21.1, build 7641a569

I created a volume using the following via a Dockerfile

    # Reference SQL image
    FROM microsoft/mssql-server-windows-developer

    # Create directory within SQL container for database files mapped to the    volume
    VOLUME sqldata:c:/MSSQL

and here it shows:
    C:\ProgramData\Docker\volumes>docker volume ls
    local               sqldata

Now I've tried probably 60+ different "solutions" based on StackOverflow and Docker forums, but none of them work. (Note despite the names below with Azure I am simply trying to get this to run locally, Azure is next hurdle)

    Docker-compose.yaml:

    version: '3.4'
    services:
      ws:
        image: wsManager
        container_name: azure-wcf
        ports:
           - "80"
        depends_on:
            - db

      db:
        image: dbimage:latest
        container_name: azure-db
        volumes:
             - \sqldata:/mssql
#            - type: volume
#              source: sqldata
#              target: /mssql
        ports:
            - "1433"

I've added a volumes section but it does not help, 

    volumes:
        sqldata:
            external:
                name: sqldata

    changed the - \sqldata:/mssql
    to every possible slash .. . ~ whatever.  Moved the file to yaml file 

到C:\ProgramData\Docker\volumes-基本上在搜索结果中显示的任何建议。 dbImage是一个SQL Server镜像,我需要保留其中的数据,但我想知道魔术是什么,因为我尝试过的所有方法都无法正常工作。任何帮助是极大的赞赏。

我正在Windows 10 Pro内部版本1803上运行。

为什么这必须这么难?
比起您,任何人都知道如何真正做到这一点。

最佳答案

解决方案是使用以下volumes选项在Windows上引用真实路径:

sqldb:
    image: sqlimage 
    container_name: azure-db
    volumes:
      - "C:\\ProgramData\\Docker\\volumes\\sqldata:c:\\mssql"

为了持久保存数据,我使用了以下内容:
environment:
   - "sa_password=ddsql2017@@"
   - "ACCEPT_EULA=Y"
   - 'attach_dbs= {"dbName":"MyDb","dbFiles":"C:\\MSSQL\\MyDb.mdf","C:\\MSSQL\\MyDb.ldf"]}]'

希望这对其他人有帮助,因为我发现在SO和其他地方搜索的许多示例都不适用于我,并且在Docker论坛上有很多帖子都说安装卷不适用于Windows。

关于Windows卷上的docker-compose无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50959475/

相关文章:

macos - 容器内的 Docker 套接字权限

docker - 如何使用 docker-compose 在容器和主机之间同步代码?

github - 如何在 github-action 中缓存 docker-compose 构建

django - 如何更新使用 docker-compose 部署的 django 应用程序?现在似乎运行旧版本的代码

docker - 获取所有docker compose依赖项的版本列表?

docker - Symfony 4 生成 SQLSTATE[HY000] [2002] 使用 Docker 容器拒绝连接

visual-studio-code - VSCode : Custom YAML formatting rules

amazon-web-services - 使用 Cloudformation 脚本创建 GlueSecurityConfiguration 时出错

ruby-on-rails - 在 rails i18n 语言环境文件中使用 YAML block

Kubernetes:集群外持久存储策略