nerdexam
Cisco

300-915 · Question #35

Drag and Drop Question Drag and drop the Dockerfile instructions from the left onto the correct arguments on the right. Answer:

The correct answer is FROM; ADD; WORKDIR; RUN; EXPOSE. Dockerfile Instruction Ordering Explained The correct order reflects the logical build sequence Docker follows when constructing an image layer by layer. --- 1. FROM Must always be first. It declares the base image (e.g., FROM ubuntu:22.04). Every subsequent instruction builds on

Application Development

Question

Drag and Drop Question Drag and drop the Dockerfile instructions from the left onto the correct arguments on the right. Answer:

Exhibit

300-915 question #35 exhibit

Answer Area

Drag items

EXPOSEADDWORKDIRRUNFROM

Correct arrangement

  • FROM
  • ADD
  • WORKDIR
  • RUN
  • EXPOSE

Explanation

Dockerfile Instruction Ordering Explained

The correct order reflects the logical build sequence Docker follows when constructing an image layer by layer.


1. FROM

Must always be first. It declares the base image (e.g., FROM ubuntu:22.04). Every subsequent instruction builds on top of it. Without a base image, Docker has nothing to work with - no filesystem, no environment, nothing.

Common mistake: Thinking you can put RUN or ENV before FROM. You can't - Docker will error immediately.


2. ADD

Copies files/directories (or URLs/tarballs) from the host into the image. It comes early because the files it copies are often needed by subsequent steps - config files, source code, scripts that RUN will execute.

Common mistake: Confusing ADD with COPY. ADD has extra powers (auto-extracts tarballs, fetches URLs), but COPY is preferred when you just need to copy local files. Either way, both go before steps that use those files.


3. WORKDIR

Sets the working directory for all subsequent instructions (RUN, CMD, ENTRYPOINT, COPY, ADD). It comes after files are added so the directory context is established before any commands are executed against those files.

Common mistake: Placing WORKDIR after RUN. If RUN executes a script that depends on relative paths, it needs WORKDIR set first or it'll run from the wrong directory.


4. RUN

Executes commands inside the image at build time (installs packages, compiles code, etc.). It comes after ADD/WORKDIR because:

  • It often operates on files that ADD copied in
  • It needs WORKDIR set so relative paths resolve correctly

Common mistake: Running RUN before ADD when the command depends on files being present, causing a "file not found" build failure.


5. EXPOSE

Documents which port(s) the container listens on at runtime. It's purely metadata - it doesn't actually open ports, it just signals intent to Docker and users. It goes last because it's a runtime declaration, not a build-time action, and has no dependency on any other instruction.

Common mistake: Thinking EXPOSE actually publishes a port. It doesn't - you still need -p in docker run or ports: in Compose to bind to the host.


The Mental Model

FROM      → what we're starting with
ADD       → bring in our files
WORKDIR   → set our location
RUN       → build/install using those files
EXPOSE    → declare runtime behavior

Each step depends on the ones before it. This layered dependency is exactly why order matters in Dockerfiles.

Topics

#Dockerfile#Container Images#Docker

Community Discussion

No community discussion yet for this question.

Full 300-915 Practice