如何使用docker-compose.override.yml为App_Data文件夹添加卷?

时间:2018-09-18 17:24:30

标签: visual-studio docker docker-compose docker-windows

我正在尝试使用Visual Studio的docker支持,并希望为C:\inetpub\wwwroot\App_Data添加卷安装。

我的Dockerfile如下:

FROM microsoft/aspnet:4.7.1-windowsservercore-1709
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .

我的docker-compose.yml文件如下:

版本:“ 3.4”

services:
  my.app:
    image: ${DOCKER_REGISTRY}myapp
    build:
      context: .\My.App
      dockerfile: Dockerfile

现在,我已经尝试在volumes文件中指定docker-compose.override.yml的所有变体,包括:

version: '3.4'

services:
  my.app:
    volumes:
      - "C:\\inetpub\\wwwroot\\App_Data"
    ports:
      - "80"
networks:
  default:
    external:
      name: nat

services:
  my.app:
    volumes:
      - "C:\\temp\\dockerappdata1":"C:\\inetpub\\wwwroot\\App_Data"
    ports:
      - "80"
networks:
  default:
    external:
      name: nat

services:
  my.app:
    volumes:
      - type: volume
        source: "app_data"
        target: "C:\\inetpub\\wwwroot\\App_Data"
    ports:
      - "80"
networks:
  default:
    external:
      name: nat
volumes:
  app_data:

但是在所有情况下,我都无法运行该项目,它会报告compose的某种配置问题,或者在启动容器时报告此问题,并显示超级无用的消息:

encountered an error during Start: failure in a Windows system call: The compute system exited unexpectedly.

正确的语法是什么?

2 个答案:

答案 0 :(得分:1)

version: '3.4'

services:
  my.app:
    volumes:
      - "C:\\inetpub\\wwwroot\\App_Data"
    ports:
      - "80"
networks:
  default:
    external:
      name: nat

services:
  my.app:
    volumes:
      - "C:\\temp\\dockerappdata1":"C:\\inetpub\\wwwroot\\App_Data"
    ports:
      - "80"
networks:
  default:
    external:
      name: nat

services:
  my.app:
    volumes:
      - type: volume
        source: "app_data"
        target: "C:\\inetpub\\wwwroot\\App_Data"
    ports:
      - "80"
networks:
  default:
    external:
      name: nat
volumes:
  app_data:

我认为这里的问题是,您正在尝试挂载已经存在的目录。

答案 1 :(得分:0)

如果我正确理解了您的问题,您想将“ C:\ inetpub \ wwwroot \ App_Data”卷装入容器中,对吗?

如果是这种情况,则应在yaml文件中添加以下内容:

services:
  my.app:
    volumes:
      - C:\\inetpub\\wwwroot\\App_Data:C:\\temp\\dockerappdata1
     # Syntax is HOST_PATH:CONTAINER_PATH:[ro/rw] (the access mode is optional)
    ports:
      - "80"

有关语法的更多信息:https://docs.docker.com/compose/compose-file/#short-syntax-3