In the previous post we saw on how to create a .Net Core console App and use Visual Studio to automatically add Dockerfile to the project. In this post, we will see how to change the Dockerfile created by Visual Studio and rebuild the Docker image with the modified file.
Once the Dockerfile is created we
can manually exit the Docker file Add/Modify steps and rebuild the Docker image.
In this sample, we will add proxy settings to enable package restore in a
Corporate firewall environment.
FROM
mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1803 AS base
WORKDIR /app
FROM
mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1803 AS build
WORKDIR /src
COPY ["HelloExe.csproj", ""]
ARG HTTP_PROXY="http://<username>:<password>@<proxyserver>:8080"
ARG HTTPS_PROXY="http://<username>:<password>@<proxyserver>:8080"
RUN dotnet restore "./HelloExe.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "HelloExe.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "HelloExe.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
Save the Dockerfile.
Right-click the Dockerfile and select option Build Docker Image
No comments:
Post a Comment