Introduction
In the previous article, we witnessed adding Redis to the Docker container and learned more about connecting Redis container with ASP.NET Core web-api.
If you haven't read my previous article yet, I highly recommend you read it by clicking here.
DockerFile
Before going into details of creating a DockerFile, let's deep dive into the concept of DockerFile.
Docker can build images by reading instructions from a DockerFile. DockerFile is a text document that contains all the commands a user could call on the command line to assemble an image. Docker build executes the instruction from the DockerFile to create an automated build using command lines.
Create a new DockerFile by selecting "Add Docker Support" in VS
Usage
Update the DockerFile with the below instruction:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build WORKDIR /src COPY *.csproj . RUN dotnet restore COPY . . RUN dotnet build -c Release -o /app/build FROM build AS publish RUN dotnet publish -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "RadisCacheDocker.dll"]
Let's understand this DockerFile command in a step-by-step manner.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
FROM
Sets the base image to use for subsequent instructions. FROM must be the first instruction in the DockerFile.
In the above line, we have been instructing Docker to download & install the ASP.NET core runtime image from the hub repository into the container. Here, we are using a run-time image rather than a SDK image due to a number of reasons.
- Run time images are smaller in size and can easily travel across networks from hub repository to your docker host.
- An application can be quickly deployed due to smaller binaries.




TonyPosted Jun 3, 2025, 5:29 AM
Can i get the Project file of .net code