Hey guys,
I created a .Net 5 Web Api and want to add Docker support for it. I tried to get into it by playing around with a sample app. So with the terminal I create a new Web Api
mkdir project
cd project
dotnet new sln
dotnet new webapi -o Api
dotnet sln add ./Api
I check that everything is fine with
cd Api
dotnet run
call https://localhost:5001/weatherforecast in the browser
close with ctrl + c
Inside the Api project I create a Dockerfile with this content
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/aspnet
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT [ "dotnet", "Api.dll" ]
I also create a .dockerignore file with this content
.git
Dockerfile
bin/
obj/
I’m building an image with
docker build -t api .
When I now run
docker images
this image has a size of 209MB. I would like to know if this is “the right way to go” or if there is something I can improve in the Dockerfile or .dockerignore file.
Thanks in advance