Skip to content

Commit cd4aef6

Browse files
this commit reduces docker image size from 233MB to 123MB using publish-only alpine image
1 parent 2452cad commit cd4aef6

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

Dockerfile

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
1-
# use ASP.NET Core 9.0 runtime image as base
2-
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
1+
# use ASP.NET Core 9.0 runtime image (alpine) as base
2+
FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine AS base
33
WORKDIR /app
44
EXPOSE 8080
55

6-
# use SDK image for build
7-
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
6+
# use SDK image (Alpine) for build
7+
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
88
WORKDIR /src
99

10-
# copy project files to restore dependencies
10+
# copy only csproj and sln to restore as early as possible
1111
COPY ["Source/Vinder.Federation.WebApi/Vinder.Federation.WebApi.csproj", "Vinder.Federation.WebApi/"]
12-
13-
# copy the entire solution 'n related projects
1412
COPY ["Vinder.Federation.sln", "./"]
1513

16-
# restore dependencies for the project
14+
# restore dependencies
1715
RUN dotnet restore "Vinder.Federation.WebApi/Vinder.Federation.WebApi.csproj"
1816

19-
# copy all source code into the container
17+
# copy the rest of the source code
2018
COPY Source/ ./Source/
2119

22-
# set working directory to the web project
2320
WORKDIR "/src/Source/Vinder.Federation.WebApi"
2421

2522
# build in Release mode
2623
RUN dotnet build "Vinder.Federation.WebApi.csproj" -c Release -o /app/build
2724

2825
# publish the project for production
29-
FROM build AS publish
3026
RUN dotnet publish "Vinder.Federation.WebApi.csproj" -c Release -o /app/publish /p:UseAppHost=false
3127

3228
# final image to run the app
3329
FROM base AS final
3430
WORKDIR /app
3531

36-
# copy published files from the publish stage
37-
COPY --from=publish /app/publish .
32+
ENV ASPNETCORE_URLS=http://+:8080
33+
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true
34+
35+
# copy published files from the build stage
36+
COPY --from=build /app/publish .
3837

39-
# set the command to start the application
4038
ENTRYPOINT ["dotnet", "Vinder.Federation.WebApi.dll"]

0 commit comments

Comments
 (0)