无法执行,因为找不到应用程序或未安装兼容的 .NET SDK [英] Could not execute because the application was not found or a compatible .NET SDK is not installed
问题描述
我使用 ASP.NET Core 5 创建了一个基本的 Rest API,我想让它与 docker 一起运行.该应用程序在 IIS Express 上运行良好.
我还想创建一个 docker 容器以启动应用程序.
在项目文件夹中,我创建了一个包含多个文件的 Docker 文件夹.这是我的 App.dockerfile:
来自 mcr.microsoft.com/dotnet/aspnet:5.0ARG WEBAPP_VERSION=0.0.1标签维护者=anymail@email_server.com 名称=webapp 版本=${WEBAPP_VERSION}ARG URL_PORT工作目录/应用程序ENV NUGET_XMLDOC_MODE 跳过ENV ASPNETCORE_URLS http://*:${URL_PORT}入口点[dotnet",WebApplication.dll";]
我也有一个 Build.docker 文件:
来自 mcr.microsoft.com/dotnet/aspnet:5.0##可以是调试或发布.ARG BUILD_CONFIG=调试ARG BUILDER_VERSION=0.0.1标签维护者=some_email@email_server.com 名称=webapp-build-${BUILD_CONFIG} 版本=${BUILDER_VERSION}## 将是映射到外部卷的路径.ARG BUILD_LOCATION=/app/outENV NUGET_XMLDOC_MODE 跳过工作目录/应用程序复制 *.csproj .运行 dotnet 还原复制 ./应用程序运行 dotnet 发布 --output ${BUILD_LOCATION} --configuration ${BUILD_CONFIG}
最后我有一个 docker-compose.yml
版本:'3'服务:网络应用程序:容器名称:webapp.test图片:webapp:${WEBAPP_VERSION}建造:语境: ../dockerfile: ./Docker/App.dockerfile参数:WEBAPP_VERSION:${WEBAPP_VERSION}URL_PORT:${URL_PORT}端口:- 5000:${URL_PORT}"卷:- 应用程序构建:/应用程序链接:- mysql环境:MYSQL_SERVER_NAME:${MYSQL_SERVER_NAME}环境文件:- 秘密.env取决于:- 建设者建设者:容器名称:建造者图片:webapp:${BUILDER_VERSION}.${BUILD_CONFIG}建造:语境: ../dockerfile: ./Docker/Build.dockerfile参数:BUILDER_VERSION:${BUILDER_VERSION}BUILD_CONFIG:${BUILD_CONFIG}BUILD_LOCATION:${BUILD_LOCATION}卷:- appbuild:${BUILD_LOCATION}mysql:容器名称:${MYSQL_SERVER_NAME}图像:mysql/mysql-server:8.0.23重启:总是卷:- dbvol:/var/lib/mysql环境:MYSQL_RANDOM_ROOT_PASSWORD:root环境文件:- 秘密.env卷:应用程序构建:数据库卷:
最后,我启动以下命令行:
docker build -f Docker/App.dockerfile -t webapp:Debug --build-arg URL_PORT=7909 .
这个过程相当快.我也启动了这个命令行:
docker run --name webapp.test -p 5000:7909 -it webapp:Debug
不幸的是,我收到一条错误消息.
无法执行,因为找不到应用程序或未安装兼容的 .NET SDK.可能的原因包括:* 您打算执行 .NET 程序:应用程序WebApplication.dll"不存在.* 您打算执行 .NET SDK 命令:找不到任何已安装的 .NET SDK.从以下位置安装 .NET SDK:https://aka.ms/dotnet-download
您的构建 Dockerfile 使用 ASP.NET Core 运行时容器映像:
来自 mcr.microsoft.com/dotnet/aspnet:5.0
这个容器没有 SDK,只有运行时.当你构建它时,它失败了:
RUN dotnet restore
无法执行,因为找不到应用程序或未安装兼容的 .NET SDK.并且应用程序恢复"不存在
因为 dotnet restore
命令是 SDK 命令.如果您只是使用运行时,则它不可用.
您应该将 SDK 容器用于您的构建 Dockerfile(不是您的运行时 Dockerfile,没关系):
来自 mcr.microsoft.com/dotnet/sdk:5.0
I created a basic Rest API using ASP.NET Core 5 i want to make run with docker. The application works fine on IIS Express.
I also want to create a docker container in order to launch the application.
In the project folder i created a Docker folder with several files. Here is my App.dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0
ARG WEBAPP_VERSION=0.0.1
LABEL maintainer=anymail@email_server.com
Name=webapp
Version=${WEBAPP_VERSION}
ARG URL_PORT
WORKDIR /app
ENV NUGET_XMLDOC_MODE skip
ENV ASPNETCORE_URLS http://*:${URL_PORT}
ENTRYPOINT [ "dotnet", "WebApplication.dll" ]
I also have a Build.docker file:
FROM mcr.microsoft.com/dotnet/aspnet:5.0
## Can be Debug or Release.
ARG BUILD_CONFIG=Debug
ARG BUILDER_VERSION=0.0.1
LABEL maintainer=some_email@email_server.com
Name=webapp-build-${BUILD_CONFIG}
Version=${BUILDER_VERSION}
## Will be the path mapped to the external volume.
ARG BUILD_LOCATION=/app/out
ENV NUGET_XMLDOC_MODE skip
WORKDIR /app
COPY *.csproj .
RUN dotnet restore
COPY . /app
RUN dotnet publish --output ${BUILD_LOCATION} --configuration ${BUILD_CONFIG}
Finally I have a docker-compose.yml
version: '3'
services:
webapp:
container_name: webapp.test
image: webapp:${WEBAPP_VERSION}
build:
context: ../
dockerfile: ./Docker/App.dockerfile
args:
WEBAPP_VERSION: ${WEBAPP_VERSION}
URL_PORT: ${URL_PORT}
ports:
- "5000:${URL_PORT}"
volumes:
- appbuild:/app
links:
- mysql
environment:
MYSQL_SERVER_NAME: ${MYSQL_SERVER_NAME}
env_file:
- secrets.env
depends_on:
- builder
builder:
container_name: builder
image: webapp:${BUILDER_VERSION}.${BUILD_CONFIG}
build:
context: ../
dockerfile: ./Docker/Build.dockerfile
args:
BUILDER_VERSION: ${BUILDER_VERSION}
BUILD_CONFIG: ${BUILD_CONFIG}
BUILD_LOCATION: ${BUILD_LOCATION}
volumes:
- appbuild:${BUILD_LOCATION}
mysql:
container_name: ${MYSQL_SERVER_NAME}
image: mysql/mysql-server:8.0.23
restart: always
volumes:
- dbvol:/var/lib/mysql
environment:
MYSQL_RANDOM_ROOT_PASSWORD: root
env_file:
- secrets.env
volumes:
appbuild:
dbvol:
Finally, I launch the following command line :
docker build -f Docker/App.dockerfile -t webapp:Debug --build-arg URL_PORT=7909 .
the process is rather quick. I also launch this command line :
docker run --name webapp.test -p 5000:7909 -it webapp:Debug
I unfortunatelly obtain an error message.
Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
* You intended to execute a .NET program:
The application 'WebApplication.dll' does not exist.
* You intended to execute a .NET SDK command:
It was not possible to find any installed .NET SDKs.
Install a .NET SDK from:
https://aka.ms/dotnet-download
Your build Dockerfile uses the ASP.NET Core runtime container image:
FROM mcr.microsoft.com/dotnet/aspnet:5.0
This container doesn't have an SDK, just the runtime. When you build it, it fails:
RUN dotnet restore
Could not execute because the application was not found or a compatible .NET SDK is not installed. and The application 'restore' does not exist
Because the dotnet restore
command is an SDK command. It's not available if you are just using the runtime.
You should use the SDK container for your build Dockerfile (not your runtime Dockerfile, that's fine):
FROM mcr.microsoft.com/dotnet/sdk:5.0
这篇关于无法执行,因为找不到应用程序或未安装兼容的 .NET SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!