liveBook · Manning

Dockerfile instruction

As explained in .NET in Action, Second Edition

A Dockerfile instruction is a directive written with an instruction keyword and arguments that controls image construction.

A Dockerfile instruction is a directive written as INSTRUCTION arguments that controls image construction. Dockerfiles may contain comments and instructions, and must begin with FROM. FROM selects a base image, which Docker modifies into a new immutable image. section 13.3.1

A practical Dockerfile combines instructions that:

  • Copy application files with COPY and select the container working directory with WORKDIR. section 13.3.1
  • Publish network metadata with EXPOSE and define startup behavior with ENTRYPOINT. section 13.3.1
  • Build applications in separate stages with RUN and COPY --from, producing a smaller runtime image. 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"]

A complete Dockerfile shows base-image selection, file copying, working-directory configuration, port exposure, and application startup. section 13.3.1

Multi-stage image construction

A build stage runs dotnet publish into /publish. A second ASP.NET runtime stage copies that output, exposes port 80, and starts AsciiArtSvc.dll with ENTRYPOINT. section 13.3.1

How .NET in Action, Second Edition covers it

How deep it goes
Defines syntax, base images, copying, startup, caching, and multi-stage builds, but not the full Dockerfile language.
Examples
Uses AsciiArtSvc Dockerfiles, .dockerignore entries, Docker build commands, and named build stages.
What it assumes
Assumes Docker Desktop and a working docker command, while introducing Dockerfile syntax from its basic elements.
What you can do after
Operate/configure Docker to build and start a tagged .NET container image.
How it connects
Connects Dockerfile instructions with base images, immutable images, multi-stage builds, .dockerignore, and Docker image tags.

Also explained in

Compare how 3 books explain Dockerfile 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.