From 772040a3f6b44cd82b4b6ac4047b650d0233d3b9 Mon Sep 17 00:00:00 2001 From: Adam Ross Date: Mon, 19 Nov 2018 16:29:19 -0800 Subject: [PATCH] serving/samples/helloworld-csharp: simplify and standardize Dockerfile (#500) --- serving/samples/helloworld-csharp/Dockerfile | 22 +++++++++++++------ serving/samples/helloworld-csharp/README.md | 23 +++++++++++++++----- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/serving/samples/helloworld-csharp/Dockerfile b/serving/samples/helloworld-csharp/Dockerfile index 31dd35163..1bf2cab0b 100644 --- a/serving/samples/helloworld-csharp/Dockerfile +++ b/serving/samples/helloworld-csharp/Dockerfile @@ -1,14 +1,22 @@ +# Use Microsoft's official .NET image. +# https://hub.docker.com/r/microsoft/dotnet FROM microsoft/dotnet:2.1-sdk -WORKDIR /app -# copy csproj and restore as distinct layers -COPY *.csproj ./ +# Install production dependencies. +# Copy csproj and restore as distinct layers. +WORKDIR /app +COPY *.csproj . RUN dotnet restore -# copy and build everything else -COPY . ./ +# Copy local code to the container image. +COPY . . + +# Build a release artifact. RUN dotnet publish -c Release -o out -EXPOSE 8080 +# Configure and document the service HTTP port. +ENV PORT 8080 +EXPOSE $PORT -ENTRYPOINT ["dotnet", "out/helloworld-csharp.dll"] +# Run the web service on container startup. +CMD ["dotnet", "out/helloworld-csharp.dll"] diff --git a/serving/samples/helloworld-csharp/README.md b/serving/samples/helloworld-csharp/README.md index 6987e300f..58d780371 100644 --- a/serving/samples/helloworld-csharp/README.md +++ b/serving/samples/helloworld-csharp/README.md @@ -55,17 +55,28 @@ recreate the source files from this folder. 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 + # Use Microsoft's official .NET image. + # https://hub.docker.com/r/microsoft/dotnet FROM microsoft/dotnet:2.1-sdk - WORKDIR /app - # copy csproj and restore as distinct layers - COPY *.csproj ./ + # Install production dependencies. + # Copy csproj and restore as distinct layers. + WORKDIR /app + COPY *.csproj . RUN dotnet restore - # copy and build everything else - COPY . ./ + # Copy local code to the container image. + COPY . . + + # Build a release artifact. RUN dotnet publish -c Release -o out - ENTRYPOINT ["dotnet", "out/helloworld-csharp.dll"] + + # Configure and document the service HTTP port. + ENV PORT 8080 + EXPOSE $PORT + + # Run the web service on container startup. + CMD ["dotnet", "out/helloworld-csharp.dll"] ``` 1. Create a new file, `service.yaml` and copy the following service definition