Skip to content

Commit 533e6b7

Browse files
mattwelkeknative-prow-robot
authored andcommitted
[Sample] Update C# hello world serving sample according to Microsoft docs, to multistep build (#1732)
* Updated C# hello-world sample to multistep build, removed .dockerignore file. * Restore .dockerignore file, restore comments in Dockerfile to match rest of samples. Change link in Dockerfile to point to Microsoft site, not Docker Hub. * Updated Dockerfile to have Docker Hub links, with link comment for each stage of build. Updated README.md file to reflect new Dockerfile. * Restore step for creating .dockerignore file to readme. * Updated Dockerfile to use trailing slash for COPY steps. * Clarify comment for each image in Dockerfile. Update readme with new Dockerfile.
1 parent 89c6b54 commit 533e6b7

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Dockerfile
22
README.md
33
**/obj/
4-
**/bin/
4+
**/bin/
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
# Use Microsoft's official .NET image.
2-
# https://hub.docker.com/r/microsoft/dotnet
3-
FROM microsoft/dotnet:2.2-sdk
1+
# Use Microsoft's official build .NET image.
2+
# https://hub.docker.com/_/microsoft-dotnet-core-sdk/
3+
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
4+
WORKDIR /app
45

56
# Install production dependencies.
67
# Copy csproj and restore as distinct layers.
7-
WORKDIR /app
8-
COPY *.csproj .
8+
COPY *.csproj ./
99
RUN dotnet restore
1010

1111
# Copy local code to the container image.
12-
COPY . .
12+
COPY . ./
13+
WORKDIR /app
1314

1415
# Build a release artifact.
1516
RUN dotnet publish -c Release -o out
1617

18+
19+
# Use Microsoft's official runtime .NET image.
20+
# https://hub.docker.com/_/microsoft-dotnet-core-aspnet/
21+
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
22+
WORKDIR /app
23+
COPY --from=build /app/out ./
24+
1725
# Run the web service on container startup.
18-
CMD ["dotnet", "out/helloworld-csharp.dll"]
26+
ENTRYPOINT ["dotnet", "helloworld-csharp.dll"]

docs/serving/samples/hello-world/helloworld-csharp/README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,37 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-csharp
6969
```
7070

7171
1. In your project directory, create a file named `Dockerfile` and copy the code
72-
block below into it. For detailed instructions on dockerizing a .NET core
72+
block below into it. For detailed instructions on dockerizing an ASP.NET Core
7373
app, see
74-
[dockerizing a .NET core app](https://docs.microsoft.com/en-us/dotnet/core/docker/docker-basics-dotnet-core#dockerize-the-net-core-application).
74+
[Docker images for ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images).
7575

7676
```docker
77-
# Use Microsoft's official .NET image.
78-
# https://hub.docker.com/r/microsoft/dotnet
79-
FROM microsoft/dotnet:2.2-sdk
80-
77+
# Use Microsoft's official build .NET image.
78+
# https://hub.docker.com/_/microsoft-dotnet-core-sdk/
79+
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
80+
WORKDIR /app
81+
8182
# Install production dependencies.
8283
# Copy csproj and restore as distinct layers.
83-
WORKDIR /app
84-
COPY *.csproj .
84+
COPY *.csproj ./
8585
RUN dotnet restore
86-
86+
8787
# Copy local code to the container image.
88-
COPY . .
89-
88+
COPY . ./
89+
WORKDIR /app
90+
9091
# Build a release artifact.
9192
RUN dotnet publish -c Release -o out
92-
93+
94+
95+
# Use Microsoft's official runtime .NET image.
96+
# https://hub.docker.com/_/microsoft-dotnet-core-aspnet/
97+
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
98+
WORKDIR /app
99+
COPY --from=build /app/out ./
100+
93101
# Run the web service on container startup.
94-
CMD ["dotnet", "out/helloworld-csharp.dll"]
102+
ENTRYPOINT ["dotnet", "helloworld-csharp.dll"]
95103
```
96104

97105
1. Create a `.dockerignore` file to ensure that any files related to a local

0 commit comments

Comments
 (0)