7

我正在尝试创建一个 Dockerfile 以及一个 docker-compose.yml 文件以dotnet watch run在多项目 ASP.Net Core 解决方案上运行。目标是让容器监视所有三个项目的变化。

我的解决方案结构是这样的:

Nc.Application
Nc.Domain
Nc.Infrastructure
docker-compose.yml

Nc.Application包含要运行的主项目,另外两个文件夹是主项目引用的.Net标准项目。在里面Nc.Application我有一个文件夹,Docker,我的 dockerfile。

Controllers
Docker
  Development.Dockerfile
Properties
Program.cs
Startup.cs
...

我的 Dockerfile 和 compose 文件包含以下内容:

开发.Dockerfile

FROM microsoft/dotnet:2.1-sdk AS build
ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore", "--urls", "http://0.0.0.0:5000" ]

码头工人-compose.yml

version: '3'

services:

  nc.api:
    container_name: ncapi_dev
    image: ncapi:dev
    build:
      context: ./Nc.Application
      dockerfile: Docker/Development.Dockerfile
    volumes:
      - ncapi.volume:.
    ports:
      - "5000:5000"
      - "5001:5001"

volumes:
  ncapi.volume:

当我尝试运行时docker-compose up,出现以下错误:

ERROR: for f6d811109779_ncapi_dev  Cannot create container for service nc.api: invalid volume specification: 'nc_ncapi.volume:.:rw': invalid mount config for type "volume": invalid mount path: '.' mount path
must be absolute

ERROR: for nc.api  Cannot create container for service nc.api: invalid volume specification: 'nc_ncapi.volume:.:rw': invalid mount config for type "volume": invalid mount path: '.' mount path must be absolute
ERROR: Encountered errors while bringing up the project.

我不知道卷的路径应该是什么,因为我的想法是创建一个不直接包含文件的容器,而是在我的系统上的一个文件夹中监视文件。

有人对如何解决这个问题有任何建议吗?

编辑:

WORKDIR在 Dockerfile 中/app/Nc.Application更新为,将卷路径更新为./:/app并删除了命名卷volumes: ncapi.volume。但是,我现在收到以下错误:

ncapi_dev | watch : Polling file watcher is enabled
ncapi_dev | watch : Started
ncapi_dev | /usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1004: Assets file '/app/Nc.Application/c:/Users/Christian/Documents/source/nc/Nc.Application/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/app/Nc.Application/Nc.Application.csproj]
ncapi_dev |
ncapi_dev | The build failed. Please fix the build errors and run again.
ncapi_dev | watch : Exited with error code 1
ncapi_dev | watch : Waiting for a file to change before restarting dotnet...
4

1 回答 1

8

更新:最新的 VS Code Insiders 引入了远程开发,它允许你直接在容器中工作。值得一试。


你不应该在容器的根目录挂载东西。使用另一个挂载点,例如/app. 此外,对于这种情况,您不需要命名卷,而是绑定挂载。

进行这样的更改

开发.Dockerfile

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app
ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore", "--urls", "http://0.0.0.0:5000" ]

码头工人-compose.yml

version: '3'

services:

  nc.api:
    container_name: ncapi_dev
    image: ncapi:dev
    build:
      context: ./Nc.Application
      dockerfile: Docker/Development.Dockerfile
    volumes:
      - ./:/app
    ports:
      - "5000:5000"
      - "5001:5001"
于 2018-11-11T05:55:04.187 回答