Add > Container Orchestrator Support… . In step 4, we’ll explore this option in greater
detail.
Using an existing official .NET Docker image You usually build a custom image for your container on top of a base image you get from an official
repository like the
Docker Hub
registry. That is precisely what happens under the covers when you
enable Docker support in Visual Studio. Your Dockerfile will use an existing
dotnet/core/aspnet
image.
Earlier we explained which Docker images and repos you can use, depending on the framework and
OS you have chosen. For instance, if you want to use ASP.NET Core (Linux or Windows), the image to
use is
mcr.microsoft.com/dotnet/aspnet:7.0
. Therefore, you just need to specify what base Docker
image you will use for your container. You do that by adding
FROM
mcr.microsoft.com/dotnet/aspnet:7.0
to your Dockerfile. This will be automatically performed by
Visual Studio, but if you were to update the version, you update this value.
Using an official .NET image repository from Docker Hub with a version number ensures that the same
language features are available on all machines (including development, testing, and production).
The following example shows a sample Dockerfile for an ASP.NET Core container.
FROM mcr.microsoft.com/dotnet/aspnet:7.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT [
"dotnet"
,
" MySingleContainerWebApp.dll "
]
In this case, the image is based on version 7.0 of the official ASP.NET Core Docker image (multi-arch
for Linux and Windows). This is the setting
FROM mcr.microsoft.com/dotnet/aspnet:7.0
. (For more
information about this base image, see the
ASP.NET Core Docker Image
page.) In the Dockerfile, you
also need to instruct Docker to listen on the TCP port you will use at runtime (in this case, port 80, as
configured with the EXPOSE setting).
You can specify additional configuration settings in the Dockerfile, depending on the language and
framework you’re using. For instance, the ENTRYPOINT line with
["dotnet",
"MySingleContainerWebApp.dll"]
tells Docker to run a .NET application. If you’re using the SDK and
the .NET CLI (dotnet CLI) to build and run the .NET application, this setting would be different. The
bottom line is that the ENTRYPOINT line and other settings will be different depending on the
language and platform you choose for your application.