![](/img/trans.png)
[英]ASP.NET Core: "The project doesn't know how to run the profile Docker." on Visual Studio 2017
[英]How to run an ASP.NET Core 3.1 project in a Docker container with Visual Studio 2019?
我創建了一個基於 ASP.NET Core 3.1 框架的 Web API 項目。 后來,我決定將其部署在 Linux 上而不是 Windows VPS 上。 在 Linux VPS 上部署應用程序之前,我希望能夠在 Windows 7 上使用 Visual Studio 2019 在本地的 docker 容器中運行。
我在我的機器上安裝了適用於 Windows 的 docker 工具箱以及 Oracle VM VirtualBox。
由於我的項目不是使用 Docker 支持創建的,因此我右鍵單擊了我的項目 >> 添加 >> “添加 Docker”支持,它創建了Dockerfile
。
現在,當我嘗試在 Visual Studio 上構建/調試我的應用程序時,出現以下錯誤
Error CTC1003 Visual Studio container tools require Docker to be running. ProjectName C:\Users\MyUsername\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.9.10\build\Container.targets 198
我通過單擊“Docker Quickstart Terminal”啟動了 Docker。 我還可以驗證default
virtual-box 是否正在運行。 此外,我在默認 VM 上添加了“C_Drive”作為共享文件夾。
如何使用 docker 正確啟動/調試我的解決方案?
這里是我的Dockerfile
的內容
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["ProjectName/ProjectName.csproj", "ProjectName/"]
RUN dotnet restore "ProjectName/ProjectName.csproj"
COPY . .
WORKDIR "/src/ProjectName"
RUN dotnet build "ProjectName.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ProjectName.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProjectName.dll"]
我還嘗試通過右鍵單擊我的項目 >> 添加 >> 添加docker-compose
項目的容器 Orchestraintor 支持來添加docker-compose
支持。
當我使用Docker Composer
運行應用程序時,應用程序運行 Visual Studio 變為橙色以進行調試狀態”並立即停止。以下是我在調試窗口中得到的內容
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
https://aka.ms/dotnet-download
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program 'dotnet' has exited with code 145 (0x91).
更新 1
這是 Visual Studio 在“構建”輸出下打印的內容
1>------ Build started: Project: MyProject, Configuration: Debug Any CPU ------
1>MyProject -> C:\MyProjects\MyProject\MyProject\bin\Debug\netcoreapp3.1\MyProject.dll
1>docker run -dt -v "C:\Users\MyUsername\vsdbg\vs2017u5:/remote_debugger:rw" -v "C:\MyProjects\MyProject\MyProject:/app" -v "C:\MyProjects\MyProject:/src" -v "C:\Users\MyUsername\AppData\Roaming\Microsoft\UserSecrets:/root/.microsoft/usersecrets:ro" -v "C:\Users\MyUsername\AppData\Roaming\ASP.NET\Https:/root/.aspnet/https:ro" -v "C:\Users\MyUsername\.nuget\packages\:/root/.nuget/fallbackpackages2" -v "C:\Program Files\dotnet\sdk\NuGetFallbackFolder:/root/.nuget/fallbackpackages" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_URLS=https://+:443;http://+:80" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages2" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages;/root/.nuget/fallbackpackages2" -P --name MyProject --entrypoint tail myproject:dev -f /dev/null
1>docker: Error response from daemon: invalid mode: /root/.nuget/fallbackpackages.
1>See 'docker run --help'.
1>C:\Users\MyUsername\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.9.10\build\Container.targets(198,5): error CTC1003: Visual Studio container tools require Docker to be running.
1>Done building project "MyProject.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
這是 VS 在“Container Tools”輸出下打印的內容
========== Checking for Container Prerequisites ==========
Verifying that Docker Desktop is installed...
Docker Desktop is installed.
========== Verifying that Docker Desktop is running... ==========
Verifying that Docker Desktop is running...
Visual Studio container tools require Docker to be running.
Docker Desktop is not running.
========== Finished ==========
更新 2
根據下面的Wiebe Tijsma
回答,我將Wiebe Tijsma
docker-composer.yml
文件更新為以下內容
version: '3.4'
services:
myproject:
image: ${DOCKER_REGISTRY-}myproject
build:
context: .
dockerfile: MyProject/Dockerfile
volumes:
- photos:/app/Storage
volumes:
photos:
構建現在似乎運行良好,但運行失敗。 使用docker-composer
運行應用程序時,Visual Studio 會拋出此錯誤
啟動失敗,因為容器中的目錄“/remote_debugger”為空。 這可能是由 Docker 桌面使用的共享驅動器憑據過期造成的。 嘗試在 Docker 桌面設置的共享驅動器頁面中重置憑據,然后重新啟動 Docker
這是 Visual Studio 的最新構建輸出
1>------ Build started: Project: MyProject, Configuration: Debug Any CPU ------
1>MyProject -> C:\MyProjects\MyProject\MyProject\bin\Debug\netcoreapp3.1\MyProject.dll
2>------ Build started: Project: docker-compose, Configuration: Debug Any CPU ------
2>docker-compose -f "C:\MyProjects\MyProject\docker-compose.yml" -f "C:\MyProjects\MyProject\docker-compose.override.yml" -f "C:\MyProjects\MyProject\obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose15694150546677200279 --no-ansi up -d
2>Creating network "dockercompose15694150546677200279_default" with the default driver
2>Creating MyProject ...
2>Creating MyProject ... done
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
就我而言,發生錯誤是因為我還將一個卷映射到 /app,這基本上導致所有入口點 + 所有 dotnet 發布的文件都不可用(初學者錯誤:))。
myapp:
container_name: myapp
image: watch/myapp
volumes:
- ./testdata/:/app #<-- wrong
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.