I am trying to run .net core api in a docker container but I am getting the following error:
My first guess looking at the error is that it's because it is not able to find .net core sdk. But as you can see I have included sdk in my dockerfile: FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
Dockerfile
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
EXPOSE 80/tcp
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "ApiForDocker.dll"]
docker-compose.yml
version: '3'
services:
coreapi:
build:
context: .
dockerfile: Dockerfile
ports:
- "4002:5000"
volumes:
- .:/app
Okay I solved by removing :
volumes:
- .:/app
from my docker-compose.yml:
version: '3'
services:
coreapi:
build:
context: .
dockerfile: Dockerfile
ports:
- "4002:5000"
I guess the problem was that I building code with my dockerfile but then in docker compose I was basically saying that I want to use my source code outside to be used. It might work in nodejs but I am not sure how to use prebuilt .net code code as volume.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.