You are building a Docker image that will contain a .NET Core application. The Dockerfile includes numbered lines for reference. To ensure the final image is as small as possible, which line number in the Dockerfile should you modify?
Choose an answer
Tap an option to check your answer.
Correct answer: 4.
Why this is the answer
Line 4, COPY . ., copies the entire build context into the image. This includes source code, temporary files, and other artifacts that are not needed in the final runtime image. To minimize image size, you should use a .dockerignore file to exclude unnecessary files and directories from being copied into the image. Alternatively, you could restructure the Dockerfile to only copy the necessary build output in a multi-stage build. Line 1 (FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build) defines the build stage base image, which is necessary for compiling the application. Line 3 (WORKDIR /src) sets the working directory, which is a standard and necessary step. Line 7 (FROM mcr.microsoft.com/dotnet/aspnet:5.0) defines the runtime base image, which is optimized for size and contains only the necessary components to run the application. Modifying these lines would likely break the build or runtime environment.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed