From 4a14b3da170cd8d8a49da166986a93a83e952905 Mon Sep 17 00:00:00 2001 From: Matt Welke Date: Sat, 24 Aug 2019 14:27:36 -0400 Subject: [PATCH 1/6] Updated C# hello-world sample to multistep build, removed .dockerignore file. --- .../helloworld-csharp/.dockerignore | 4 --- .../hello-world/helloworld-csharp/Dockerfile | 19 ++++++------ .../hello-world/helloworld-csharp/README.md | 31 +++++++------------ 3 files changed, 21 insertions(+), 33 deletions(-) delete mode 100644 docs/serving/samples/hello-world/helloworld-csharp/.dockerignore diff --git a/docs/serving/samples/hello-world/helloworld-csharp/.dockerignore b/docs/serving/samples/hello-world/helloworld-csharp/.dockerignore deleted file mode 100644 index ee5e6f9ea69..00000000000 --- a/docs/serving/samples/hello-world/helloworld-csharp/.dockerignore +++ /dev/null @@ -1,4 +0,0 @@ -Dockerfile -README.md -**/obj/ -**/bin/ diff --git a/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile b/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile index ec411c343d8..56f63c19b2b 100644 --- a/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile +++ b/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile @@ -1,18 +1,19 @@ # Use Microsoft's official .NET image. # https://hub.docker.com/r/microsoft/dotnet -FROM microsoft/dotnet:2.2-sdk - -# Install production dependencies. -# Copy csproj and restore as distinct layers. +FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /app + +# copy csproj and restore as distinct layers COPY *.csproj . RUN dotnet restore -# Copy local code to the container image. +# copy everything else and build app COPY . . - -# Build a release artifact. +WORKDIR /app RUN dotnet publish -c Release -o out -# Run the web service on container startup. -CMD ["dotnet", "out/helloworld-csharp.dll"] + +FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime +WORKDIR /app +COPY --from=build /app/out ./ +ENTRYPOINT ["dotnet", "helloworld-csharp.dll"] diff --git a/docs/serving/samples/hello-world/helloworld-csharp/README.md b/docs/serving/samples/hello-world/helloworld-csharp/README.md index 249daebbdd2..c0196696540 100644 --- a/docs/serving/samples/hello-world/helloworld-csharp/README.md +++ b/docs/serving/samples/hello-world/helloworld-csharp/README.md @@ -69,39 +69,30 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-csharp ``` 1. In your project directory, create a file named `Dockerfile` and copy the code - block below into it. For detailed instructions on dockerizing a .NET core + block below into it. For detailed instructions on dockerizing an ASP.NET Core app, see - [dockerizing a .NET core app](https://docs.microsoft.com/en-us/dotnet/core/docker/docker-basics-dotnet-core#dockerize-the-net-core-application). + [Docker images for ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images). ```docker # Use Microsoft's official .NET image. # https://hub.docker.com/r/microsoft/dotnet - FROM microsoft/dotnet:2.2-sdk - - # Install production dependencies. - # Copy csproj and restore as distinct layers. + FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /app + + # copy csproj and restore as distinct layers COPY *.csproj . RUN dotnet restore - # Copy local code to the container image. + # copy everything else and build app COPY . . - - # Build a release artifact. + WORKDIR /app RUN dotnet publish -c Release -o out - # Run the web service on container startup. - CMD ["dotnet", "out/helloworld-csharp.dll"] - ``` - -1. Create a `.dockerignore` file to ensure that any files related to a local - build do not affect the container that you build for deployment. - ```ignore - Dockerfile - README.md - **/obj/ - **/bin/ + FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime + WORKDIR /app + COPY --from=build /app/out ./ + ENTRYPOINT ["dotnet", "helloworld-csharp.dll"] ``` 1. Create a new file, `service.yaml` and copy the following service definition From 6cb78c2e04615da6a30aba647db25692a4e53d24 Mon Sep 17 00:00:00 2001 From: Matt Welke Date: Tue, 27 Aug 2019 21:20:55 -0400 Subject: [PATCH 2/6] Restore .dockerignore file, restore comments in Dockerfile to match rest of samples. Change link in Dockerfile to point to Microsoft site, not Docker Hub. --- .../hello-world/helloworld-csharp/.dockerignore | 4 ++++ .../samples/hello-world/helloworld-csharp/Dockerfile | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 docs/serving/samples/hello-world/helloworld-csharp/.dockerignore diff --git a/docs/serving/samples/hello-world/helloworld-csharp/.dockerignore b/docs/serving/samples/hello-world/helloworld-csharp/.dockerignore new file mode 100644 index 00000000000..2a82a9c3f30 --- /dev/null +++ b/docs/serving/samples/hello-world/helloworld-csharp/.dockerignore @@ -0,0 +1,4 @@ +Dockerfile +README.md +**/obj/ +**/bin/ \ No newline at end of file diff --git a/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile b/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile index 56f63c19b2b..c2b15fb2539 100644 --- a/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile +++ b/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile @@ -1,19 +1,24 @@ # Use Microsoft's official .NET image. -# https://hub.docker.com/r/microsoft/dotnet +# https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /app -# copy csproj and restore as distinct layers +# Install production dependencies. +# Copy csproj and restore as distinct layers. COPY *.csproj . RUN dotnet restore -# copy everything else and build app +# Copy local code to the container image. COPY . . WORKDIR /app + +# Build a release artifact. RUN dotnet publish -c Release -o out FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime WORKDIR /app COPY --from=build /app/out ./ + +# Run the web service on container startup. ENTRYPOINT ["dotnet", "helloworld-csharp.dll"] From ca2d2808ffb46733c58dbda64e65453b8efea32a Mon Sep 17 00:00:00 2001 From: Matt Welke Date: Thu, 29 Aug 2019 22:09:30 -0400 Subject: [PATCH 3/6] Updated Dockerfile to have Docker Hub links, with link comment for each stage of build. Updated README.md file to reflect new Dockerfile. --- .../hello-world/helloworld-csharp/Dockerfile | 4 +++- .../hello-world/helloworld-csharp/README.md | 21 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile b/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile index c2b15fb2539..c425e3387af 100644 --- a/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile +++ b/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile @@ -1,5 +1,5 @@ # Use Microsoft's official .NET image. -# https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images +# https://hub.docker.com/_/microsoft-dotnet-core-sdk/ FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /app @@ -16,6 +16,8 @@ WORKDIR /app RUN dotnet publish -c Release -o out +# Use Microsoft's official .NET image. +# https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime WORKDIR /app COPY --from=build /app/out ./ diff --git a/docs/serving/samples/hello-world/helloworld-csharp/README.md b/docs/serving/samples/hello-world/helloworld-csharp/README.md index c0196696540..04a1b8fd011 100644 --- a/docs/serving/samples/hello-world/helloworld-csharp/README.md +++ b/docs/serving/samples/hello-world/helloworld-csharp/README.md @@ -75,23 +75,30 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-csharp ```docker # Use Microsoft's official .NET image. - # https://hub.docker.com/r/microsoft/dotnet + # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /app - - # copy csproj and restore as distinct layers + + # Install production dependencies. + # Copy csproj and restore as distinct layers. COPY *.csproj . RUN dotnet restore - - # copy everything else and build app + + # Copy local code to the container image. COPY . . WORKDIR /app + + # Build a release artifact. RUN dotnet publish -c Release -o out - - + + + # Use Microsoft's official .NET image. + # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime WORKDIR /app COPY --from=build /app/out ./ + + # Run the web service on container startup. ENTRYPOINT ["dotnet", "helloworld-csharp.dll"] ``` From 2968cdea397dd860a24a27ff987ecd54645064b4 Mon Sep 17 00:00:00 2001 From: Matt Welke Date: Thu, 29 Aug 2019 22:34:02 -0400 Subject: [PATCH 4/6] Restore step for creating .dockerignore file to readme. --- .../samples/hello-world/helloworld-csharp/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/serving/samples/hello-world/helloworld-csharp/README.md b/docs/serving/samples/hello-world/helloworld-csharp/README.md index 04a1b8fd011..cc91c8016b5 100644 --- a/docs/serving/samples/hello-world/helloworld-csharp/README.md +++ b/docs/serving/samples/hello-world/helloworld-csharp/README.md @@ -102,6 +102,16 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-csharp ENTRYPOINT ["dotnet", "helloworld-csharp.dll"] ``` +1. Create a `.dockerignore` file to ensure that any files related to a local + build do not affect the container that you build for deployment. + + ```ignore + Dockerfile + README.md + **/obj/ + **/bin/ + ``` + 1. Create a new file, `service.yaml` and copy the following service definition into the file. Make sure to replace `{username}` with your Docker Hub username. From 3a6a3438546a70400ee5f14be0be774b56f75289 Mon Sep 17 00:00:00 2001 From: Matt Welke Date: Fri, 30 Aug 2019 10:40:08 -0400 Subject: [PATCH 5/6] Updated Dockerfile to use trailing slash for COPY steps. --- docs/serving/samples/hello-world/helloworld-csharp/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile b/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile index c2b15fb2539..433dd9382d2 100644 --- a/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile +++ b/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile @@ -5,11 +5,11 @@ WORKDIR /app # Install production dependencies. # Copy csproj and restore as distinct layers. -COPY *.csproj . +COPY *.csproj ./ RUN dotnet restore # Copy local code to the container image. -COPY . . +COPY . ./ WORKDIR /app # Build a release artifact. From e1e357a539ef54e1c4df095536e1dbcb3e72c659 Mon Sep 17 00:00:00 2001 From: Matt Welke Date: Fri, 30 Aug 2019 10:44:19 -0400 Subject: [PATCH 6/6] Clarify comment for each image in Dockerfile. Update readme with new Dockerfile. --- .../samples/hello-world/helloworld-csharp/Dockerfile | 4 ++-- .../samples/hello-world/helloworld-csharp/README.md | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile b/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile index 0f7d71357e2..1209aaa1d87 100644 --- a/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile +++ b/docs/serving/samples/hello-world/helloworld-csharp/Dockerfile @@ -1,4 +1,4 @@ -# Use Microsoft's official .NET image. +# Use Microsoft's official build .NET image. # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /app @@ -16,7 +16,7 @@ WORKDIR /app RUN dotnet publish -c Release -o out -# Use Microsoft's official .NET image. +# Use Microsoft's official runtime .NET image. # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime WORKDIR /app diff --git a/docs/serving/samples/hello-world/helloworld-csharp/README.md b/docs/serving/samples/hello-world/helloworld-csharp/README.md index cc91c8016b5..ceffad6f033 100644 --- a/docs/serving/samples/hello-world/helloworld-csharp/README.md +++ b/docs/serving/samples/hello-world/helloworld-csharp/README.md @@ -74,25 +74,25 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-csharp [Docker images for ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/building-net-docker-images). ```docker - # Use Microsoft's official .NET image. + # Use Microsoft's official build .NET image. # https://hub.docker.com/_/microsoft-dotnet-core-sdk/ FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build WORKDIR /app # Install production dependencies. # Copy csproj and restore as distinct layers. - COPY *.csproj . + COPY *.csproj ./ RUN dotnet restore # Copy local code to the container image. - COPY . . + COPY . ./ WORKDIR /app # Build a release artifact. RUN dotnet publish -c Release -o out - # Use Microsoft's official .NET image. + # Use Microsoft's official runtime .NET image. # https://hub.docker.com/_/microsoft-dotnet-core-aspnet/ FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime WORKDIR /app