I have a .Net webapi project, and I want to dockerize it. Without docker, dotnet sdk(6.0) can restore everything correctly and there is no obstacle for me to publish the app. But when I use docker to do that, it gives me tones of errors with the error codes CS0246, CS8714, CS0103, CS0535, CS0738. You can find my project folder structure and relevant information below:
src
|-->API
| |-->API.csproj
| |-->Some other stuff
tools
|-->Docker
| |-->Dockerfile
docker-compose.yml
#./src/Docker/Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /source
COPY *.sln ./
COPY ./src/API src/API
WORKDIR /src/API
RUN dotnet restore
RUN dotnet publish -c release -o /src/API
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /src/API
COPY --from=build /src/API ./
EXPOSE 80/tcp
ENV ASPNETCORE_URLS http://*:80
ENTRYPOINT ["dotnet", "API.dll"]
#./docker-compose.yml
version: '3'
services:
api:
build:
context: .
dockerfile: tools/Docker/Dockerfile
ports:
- "5009:5009"
environment:
ASPNETCORE_ENVIRONMENT: "prod"