What is the purpose of the FROM instruction in a Dockerfile?
The FROM instruction sets the base image for the Docker image you want to build. It tells Docker which existing image to start from.
Click to reveal answer
intermediate
Can a Dockerfile have multiple FROM instructions?
Yes, a Dockerfile can have multiple FROM instructions to create multi-stage builds. Each FROM starts a new stage.
Click to reveal answer
beginner
How do you specify a specific version of a base image in the FROM instruction?
You add a tag after the image name, separated by a colon. For example, FROM ubuntu:22.04 uses Ubuntu version 22.04 as the base image.
Click to reveal answer
beginner
What happens if you omit the tag in the FROM instruction?
If you omit the tag, Docker uses the 'latest' tag by default, which means it uses the most recent version of the image.
Click to reveal answer
intermediate
Why is it important to choose a small base image in the FROM instruction?
Choosing a small base image reduces the final image size, making downloads and deployments faster and saving storage space.
Click to reveal answer
What does the FROM instruction do in a Dockerfile?
ARuns a command inside the container
BSets the base image for the build
CCopies files into the image
DDefines environment variables
✗ Incorrect
The FROM instruction sets the base image that your Docker image builds upon.
How do you specify a version of an image in the FROM instruction?
AFROM image:version
BFROM image@version
CFROM version/image
DFROM image#version
✗ Incorrect
You specify the version by adding a colon and the tag after the image name, like FROM ubuntu:20.04.
What tag does Docker use if none is specified in FROM?
Astable
Bdefault
Clatest
Dbase
✗ Incorrect
Docker uses the 'latest' tag by default if no tag is specified.
Can a Dockerfile have more than one FROM instruction?
ANo, only one FROM is allowed
BYes, but only if images are the same
CNo, it causes an error
DYes, for multi-stage builds
✗ Incorrect
Multiple FROM instructions are used to create multi-stage builds.
Why choose a smaller base image in FROM?
AIt reduces image size and speeds up deployment
BIt increases security automatically
CIt is easier to write Dockerfiles
DIt has more features
✗ Incorrect
Smaller base images reduce the final image size, making downloads and deployments faster.
Explain the role of the FROM instruction in building a Docker image.
Think about how Docker knows what to build on top of.
You got /4 concepts.
Describe how to specify and why to choose a specific base image version in the FROM instruction.
Consider why you might not want to always use the latest version.
You got /5 concepts.
Practice
(1/5)
1. What does the FROM instruction do in a Dockerfile?
easy
A. It sets the base image for the Docker build.
B. It copies files from the host to the container.
C. It runs commands inside the container.
D. It exposes ports for the container.
Solution
Step 1: Understand the role of FROM
The FROM instruction defines the starting point or base image for building a Docker image.
Step 2: Compare with other instructions
Other instructions like COPY, RUN, and EXPOSE have different purposes, not setting the base image.
Final Answer:
It sets the base image for the Docker build. -> Option A
Quick Check:
FROM = base image [OK]
Hint: FROM always sets the base image in Dockerfile [OK]
Common Mistakes:
Confusing FROM with COPY or RUN instructions
Thinking FROM exposes ports
Assuming FROM copies files
2. Which of the following is the correct syntax for the FROM instruction to use the Ubuntu 22.04 image?
easy
A. FROM ubuntu/22.04
B. FROM ubuntu-22.04
C. FROM ubuntu:22.04
D. FROM ubuntu@22.04
Solution
Step 1: Recall Docker image tag syntax
The correct format is image_name:tag, so ubuntu:22.04 is valid.
Step 2: Check other options
Options with dashes, slashes, or @ are invalid for tags in FROM instruction.
Final Answer:
FROM ubuntu:22.04 -> Option C
Quick Check:
Use colon for tag in FROM [OK]
Hint: Use colon ':' to specify image tag in FROM [OK]
Common Mistakes:
Using dash '-' instead of colon ':' for tags
Using slash '/' incorrectly in image name
Using '@' instead of ':' for tags
3. Given this Dockerfile snippet:
FROM python:3.12-slim
RUN python --version
What will be the output when building this Docker image?
medium
A. Python 3.11.x
B. Python 3.12.x
C. Error: python command not found
D. Python 2.7.x
Solution
Step 1: Identify base image version
The base image is python:3.12-slim, which includes Python version 3.12.
Step 2: Understand RUN command output
The RUN command executes python --version, which prints the Python version installed in the image.
Final Answer:
Python 3.12.x -> Option B
Quick Check:
FROM python:3.12-slim runs Python 3.12 [OK]
Hint: Tag in FROM matches Python version output [OK]
Common Mistakes:
Assuming default Python version is 3.11 or 2.7
Thinking slim images lack Python
Confusing build output with runtime
4. Identify the error in this Dockerfile snippet:
FROM alpine
FROM ubuntu:20.04
RUN echo "Hello"
medium
A. FROM instruction must be last line.
B. Missing tag for alpine image causes error.
C. Multiple FROM instructions without stage names cause error.
D. There is no error in this Dockerfile snippet.
Solution
Step 1: Check multiple FROM usage
Multiple FROM instructions are allowed for multi-stage builds even without stage names (AS). Earlier stages are discarded unless referenced (by name or index).
Step 2: Verify other parts
FROM alpine defaults to :latest (valid image). The RUN applies to the final stage (ubuntu:20.04) and is syntactically correct.
Final Answer:
There is no error in this Dockerfile snippet. -> Option D
Quick Check:
Multiple FROM without AS is valid [OK]
Hint: Multiple FROM instructions do not require stage names [OK]
Common Mistakes:
Assuming multiple FROM lines always work without names
Thinking RUN syntax is wrong here
Believing FROM must be last line
5. You want to build a multi-stage Dockerfile using node:18 as the build stage (named 'build') and nginx:alpine as the final stage. Which FROM instructions correctly set this up?
hard
A. FROM node:18 AS build
FROM nginx:alpine
B. FROM node:18
FROM nginx:alpine AS build
C. FROM node:18
FROM nginx:alpine
D. FROM node:18 AS build
FROM nginx:alpine AS build
Solution
Step 1: Understand multi-stage build syntax
Use AS to name the build stage, e.g., FROM node:18 AS build.
Step 2: Set final stage without conflicting names
The final stage uses FROM nginx:alpine without a stage name or with a different name.
Step 3: Check options
FROM node:18 AS build
FROM nginx:alpine correctly names the build stage and then starts the final stage. Others misuse stage names or omit them incorrectly.
Final Answer:
FROM node:18 AS build
FROM nginx:alpine -> Option A
Quick Check:
Use AS to name build stage first [OK]
Hint: Name build stage with AS, final stage without or different name [OK]
Common Mistakes:
Naming both stages the same
Placing AS on final stage incorrectly
Omitting AS for build stage in multi-stage
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.