dotnet手表在具有多项目解决方案的容器中运行

时间:2018-11-10 12:21:36

标签: docker docker-compose

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

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

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

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

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

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

Development.Dockerfile

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

docker-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.

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

有人对此有什么建议吗?

编辑:

我将Dockerfile中的WORKDIR更新为/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...

1 个答案:

答案 0 :(得分:1)

更新:最新的VS Code Insiders引入了Remote Development,可让您直接work inside a container。值得检查一下。


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

进行这样的更改

Development.Dockerfile

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

docker-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"