The*_*ler 5 c# docker .net-core docker-compose
当我尝试dotnet watch
通过 docker(在 Windows 上,wsl)运行时,我收到类似 的错误Unhandled exception. System.ArgumentException: An item with the same key has already been added. Key: /src/bin/Debug/net5.0/Tickets.runtimeconfig.json
。总是Key: ...
不同的。
构建时有时会出现此错误:
app-watch_1 | Building...
app-watch_1 | Unhandled exception. System.ArgumentException: An item with the same key has already been added. Key: /src/bin/Debug/net5.0/Tickets.runtimeconfig.json
Run Code Online (Sandbox Code Playgroud)
但有时构建成功,但有时会随机出现错误。
即使在干净的项目中似乎也会发生这种情况。我使用以下命令创建了一个新项目(这是仍然有效的部分):
dotnet new web
然后添加一个docker文件:
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers as an optimizations
COPY *.csproj ./
RUN dotnet restore
# Copy the rest
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image without all the bagage from the build steps
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Tickets.dll"]
Run Code Online (Sandbox Code Playgroud)
添加了一个docker-compose.yml
文件:
version: '3.4'
services:
tickets:
build:
context: .
ports:
- 8880:80
Run Code Online (Sandbox Code Playgroud)
并使用以下命令运行它:docker-compose build
然后docker-compose up
. 这很好用。
然后我尝试将服务添加到我的 docker-compose 文件中以供使用dotnet watch
:
(完整的 docker 文件)
version: '3.4'
services:
tickets:
build:
context: .
ports:
- 8880:80
tickets-watch:
image: mcr.microsoft.com/dotnet/sdk:5.0
ports:
- 8881:80
volumes:
- ./:/src
working_dir: /src
command: dotnet watch run --urls=http://+:80
Run Code Online (Sandbox Code Playgroud)
当我再次尝试时docker-compose up
,有时会出现错误。其他时候构建会成功。看起来只要构建成功一次就可以了。但是当我退出 docker,删除bin
和obj
文件夹,然后再次启动 docker 时,它再次有可能会失败。
以下是我尝试过的一些事情(我确信我尝试了更多的东西,但无法记住所有内容,对此感到抱歉。):
我认为这可能与我在同一文件夹中打开 VSCode 有关,所以我添加了一个Directory.Build.props
文件:
<Project>
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);$(MSBuildProjectDirectory)/obj/**/*</DefaultItemExcludes>
<DefaultItemExcludes>$(DefaultItemExcludes);$(MSBuildProjectDirectory)/bin/**/*</DefaultItemExcludes>
</PropertyGroup>
<PropertyGroup Condition="'$(DOTNET_RUNNING_IN_CONTAINER)' == 'true'">
<BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/obj/container/</BaseIntermediateOutputPath>
<BaseOutputPath>$(MSBuildProjectDirectory)/bin/container/</BaseOutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(DOTNET_RUNNING_IN_CONTAINER)' != 'true'">
<BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/obj/local/</BaseIntermediateOutputPath>
<BaseOutputPath>$(MSBuildProjectDirectory)/bin/local/</BaseOutputPath>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
那没有帮助。
我还删除了 docker 桌面,并在 WSL 中安装了 docker(如下: https: //dev.to/bowmanjd/install-docker-on-windows-wsl-without-docker-desktop-34m9),但这也没有帮助。
我尝试在我的 Linux 电脑上运行相同的项目,它运行得很好。所以 def 似乎是 windows/wsl 的东西。
谢谢!
我相信我自己解决了这个问题,方法是将代码移动到 WSL 上的主文件夹中,而不是将其放在我的 C 驱动器上(然后通过 访问它/mnt/c/...
)。
所以,当我的代码输入时,/mnt/c/Users/Pablo/Dev/Tickets
我遇到了崩溃。
然后我把我的代码放进去~/dev/Tickets
,崩溃就消失了。
归档时间: |
|
查看次数: |
928 次 |
最近记录: |