Skip to content

Commit 9a23458

Browse files
authored
Explain the Dockerfile distinct layers approach (#18274)
1 parent e4f8439 commit 9a23458

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

aspnetcore/host-and-deploy/docker/building-net-docker-images.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: rick-anderson
44
description: Learn how to use the published .NET Core Docker images from the Docker Registry. Pull images and build your own images.
55
ms.author: riande
66
ms.custom: mvc
7-
ms.date: 01/15/2020
7+
ms.date: 05/12/2020
88
no-loc: [Blazor, "Identity", "Let's Encrypt", Razor, SignalR]
99
uid: host-and-deploy/docker/building-net-docker-images
1010
---
@@ -199,7 +199,6 @@ COPY aspnetapp/. ./aspnetapp/
199199
WORKDIR /app/aspnetapp
200200
RUN dotnet publish -c Release -o out
201201

202-
203202
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
204203
WORKDIR /app
205204
COPY --from=build /app/aspnetapp/out ./
@@ -235,21 +234,15 @@ COPY aspnetapp/. ./aspnetapp/
235234
WORKDIR /app/aspnetapp
236235
RUN dotnet publish -c Release -o out
237236

238-
239237
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime
240238
WORKDIR /app
241239
COPY --from=build /app/aspnetapp/out ./
242240
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
243241
```
244242

245-
::: moniker-end
243+
As noted in the preceding Dockerfile, the `*.csproj` files are copied and restored as distinct *layers*. When the `docker build` command builds an image, it uses a built-in cache. If the `*.csproj` files haven't changed since the `docker build` command last ran, the `dotnet restore` command doesn't need to run again. Instead, the built-in cache for the corresponding `dotnet restore` layer is reused. For more information, see [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache).
246244

247-
```dockerfile
248-
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS runtime
249-
WORKDIR /app
250-
COPY published/aspnetapp.dll ./
251-
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
252-
```
245+
::: moniker-end
253246

254247
## Additional resources
255248

0 commit comments

Comments
 (0)