liveBook · Manning

EXPOSE instruction

As explained in .NET in Action, Second Edition

The EXPOSE instruction documents a container port on which an application listens without publishing that port to the host.

EXPOSE documents the container port on which an application listens; it does not publish that port to the host. In a published .NET application, port 80 is exposed because the default HTTP port is 80 inside the container. section 13.3.1

Exposing a published ASP.NET Core application

A multistage Dockerfile uses an SDK image to publish the application, copies the output into an ASP.NET runtime image, and declares `EXPOSE 80` before starting `AsciiArtSvc.dll`. A development Dockerfile can instead declare `EXPOSE 5101` when using the Docker launch profile. section 13.3.1

Listing 13.6 Dockerfile with two build stages
FROM mcr.microsoft.com/dotnet/sdk:6.0          #1
COPY . /src
WORKDIR /src
RUN dotnet publish -o /publish                 #2
 
FROM mcr.microsoft.com/dotnet/aspnet:6.0       #3
COPY --from=0 /publish /publish                #4
WORKDIR /publish
EXPOSE 80                                      #5
ENTRYPOINT ["dotnet", "AsciiArtSvc.dll"]       #6

Inspect the complete multistage Dockerfile showing EXPOSE alongside the runtime image and application entry point. section 13.3.1

How .NET in Action, Second Edition covers it

How deep it goes
Defines the instruction and distinguishes internal exposure from host publishing through focused Dockerfile examples.
Examples
Uses ports 5101 and 80 in development and published multistage Dockerfiles.
What it assumes
Assumes familiarity with Dockerfiles, container images, and ASP.NET Core launch profiles.
What you can do after
Configure a Dockerfile with the port an ASP.NET Core application listens on inside its container.
How it connects
Connects EXPOSE with Dockerfile, container images, multistage builds, launch profiles, and image layers.

Also explained in

Compare how 2 books explain EXPOSE instruction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.