Bird
Raised Fist0
Dockerdevops~10 mins

FROM instruction for base image in Docker - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the Dockerfile to specify the base image as Ubuntu 20.04.

Docker
FROM [1]
Drag options to blanks, or click blank then click option'
Aubuntu:20.04
Bnode:14
Cpython:3.9
Dalpine:latest
Attempts:
3 left
💡 Hint
Common Mistakes
Using an unrelated base image like 'node:14' when Ubuntu is required.
Forgetting the version tag after the image name.
2fill in blank
medium

Complete the Dockerfile to use Alpine Linux as the base image.

Docker
FROM [1]
Drag options to blanks, or click blank then click option'
Adebian:10
Balpine:3.15
Cubuntu:latest
Dcentos:7
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a base image that is not Alpine Linux.
Using 'alpine:latest' when a specific version is preferred.
3fill in blank
hard

Fix the error in the Dockerfile base image specification.

Docker
FROM [1]
Drag options to blanks, or click blank then click option'
Apython3.8
Bpy:3.8
Cpython-3.8
Dpython:3.8
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'python3.8' without a colon.
Using hyphens instead of colons in the tag.
4fill in blank
hard

Fill both blanks to specify a Node.js base image with version 16 and use the slim variant.

Docker
FROM [1]:[2]-slim
Drag options to blanks, or click blank then click option'
Anode
B14
C16
Dalpine
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the version numbers or using the wrong image name.
Using 'alpine' instead of 'slim' for the variant.
5fill in blank
hard

Fill all three blanks to specify a Python base image with version 3.10 and the slim-buster variant.

Docker
FROM [1]:[2]-[3]
Drag options to blanks, or click blank then click option'
Apython
B3.10
Cslim-buster
Dbuster
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'buster' instead of 'slim-buster' for the variant.
Mixing up the order of version and variant.

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

  1. Step 1: Understand the role of FROM

    The FROM instruction defines the starting point or base image for building a Docker image.
  2. Step 2: Compare with other instructions

    Other instructions like COPY, RUN, and EXPOSE have different purposes, not setting the base image.
  3. Final Answer:

    It sets the base image for the Docker build. -> Option A
  4. 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

  1. Step 1: Recall Docker image tag syntax

    The correct format is image_name:tag, so ubuntu:22.04 is valid.
  2. Step 2: Check other options

    Options with dashes, slashes, or @ are invalid for tags in FROM instruction.
  3. Final Answer:

    FROM ubuntu:22.04 -> Option C
  4. 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

  1. Step 1: Identify base image version

    The base image is python:3.12-slim, which includes Python version 3.12.
  2. Step 2: Understand RUN command output

    The RUN command executes python --version, which prints the Python version installed in the image.
  3. Final Answer:

    Python 3.12.x -> Option B
  4. 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

  1. 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).
  2. 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.
  3. Final Answer:

    There is no error in this Dockerfile snippet. -> Option D
  4. 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

  1. Step 1: Understand multi-stage build syntax

    Use AS to name the build stage, e.g., FROM node:18 AS build.
  2. Step 2: Set final stage without conflicting names

    The final stage uses FROM nginx:alpine without a stage name or with a different name.
  3. 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.
  4. Final Answer:

    FROM node:18 AS build FROM nginx:alpine -> Option A
  5. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard