Reputation: 1499
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
Upvotes: 17
Views: 41880
Reputation: 39680
Similar to Alper Ebicoglu's answer, I found just deleting the rogue dotnet
dir fixed the problem:
C:\Program Files (x86)\dotnet
Upvotes: 0
Reputation: 116
Try installing .Net extension through Vs code
https://code.visualstudio.com/docs/languages/dotnet
Upvotes: 0
Reputation: 107
In my case volume mounting is created this kind of problem.
volumes:
- ./docker/caadminservice/certificate:/**CAAdminService**
CAAdminService is the root folder in container. We should not mount that directly with host machine. It created me this kind of problem
Upvotes: 0
Reputation: 31
Works for me when i changed
FROM mcr.microsoft.com/dotnet/core/aspnet:5.0
to:
FROM mcr.microsoft.com/dotnet/sdk:5.0
Upvotes: 0
Reputation: 93
In my case dot net SDKs were installed in different locations. A simple
where.exe dotnet
on powershell returned the following
There were 2 entries in system environment variables i.e. The one with x86 was above so it was taking precedence, so I swapped both of them and hurray it started working. Special thanks to https://www.hanselman.com/blog/dotnet-could-not-execute-because-the-application-was-not-found-or-a-compatible-net-sdk-is-not-installed
Upvotes: 5
Reputation: 493
Had the same message while trying to configure Docker Container Debugging in VS Code for .NET 6. Couple of issues:
In tasks.json of VS Code the default "target": "base"
was not working for me, because I used stage build
in Dockerfile. So I commented it out... But Docker extension needs it to inject the Debugging metadata.
Changing to "target": "build"
fixed the error.
I skipped the EXPOSE and ENV part because it worked via docker compose or while manually forwarding ports in cmd. Should be at the beginning of base/build stage:
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine as build
WORKDIR /source
EXPOSE 80 #was missing
ENV ASPNETCORE_URLS=http://+:80 #was missing
Upvotes: 0
Reputation: 9634
If you already installed the SDK and you have x64 machine;
Delete the following item from System Variables
> Path
C:\Program Files (x86)\dotnet
Upvotes: 20
Reputation: 15223
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
Upvotes: 29