A port number identifies where a networked service listens on a host or container. In Docker, exposing a port documents the container’s listening port but does not make it reachable from the host. section 13.3.1
Use port configuration to connect the host to a containerized service:
- Expose the port used inside the container, such as 5101. section 13.3.1
- Assign a host port and map it to the container port when starting the container. section 13.3.1
Mapping host port 5000 to container port 5101
A service listening on port 5101 inside the container is unreachable at http://localhost:5101 when the host assigns port 5000. Accessing http://localhost:5000 reaches the mapped service. section 13.3.1
Listing 13.2 Dockerfile for AsciiArtSvc
# Use the official .NET 6 container FROM mcr.microsoft.com/dotnet/sdk:6.0 # Copy files from the current folder on your machine to # the /src folder in the container COPY . /src # Set working directory in the container WORKDIR /src # Expose HTTP port from "docker" launch profile EXPOSE 5101 # Run the application when the container is started ENTRYPOINT ["dotnet", "run", "--launch-profile", "docker"]
Inspect the Dockerfile declaration that exposes the service’s HTTP port. section 13.3.1






