DevOps Docker & Containerization 1 — Questions and Answers
Question 1: What is a Docker image?
- A read-only template used to create Docker containers (Correct answer)
- A running instance of a containerized application
- A virtual machine snapshot for cloud deployments
- A configuration file that defines container networking
Correct answer: A read-only template used to create Docker containers
A Docker image is a read-only, layered template built from a Dockerfile that serves as the blueprint for creating containers.
Question 2: Which Dockerfile instruction sets the base image for a build?
- FROM (Correct answer)
- BASE
- IMAGE
- ORIGIN
Correct answer: FROM
The FROM instruction in a Dockerfile specifies the parent image upon which all subsequent instructions are layered.
Question 3: What command builds a Docker image from a Dockerfile in the current directory?
- docker build . (Correct answer)
- docker create .
- docker run .
- docker make .
Correct answer: docker build .
The `docker build .` command reads the Dockerfile in the current directory and builds an image using that context.
Question 4: What is the difference between a Docker container and a Docker image?
- A container is a running instance of an image; an image is a static template (Correct answer)
- A container is stored on disk while an image runs in memory
- A container can be shared on Docker Hub but an image cannot
- A container includes the OS kernel while an image does not
Correct answer: A container is a running instance of an image; an image is a static template
An image is a static, layered filesystem snapshot, while a container is a live, running process created from that image with a writable layer.
Question 5: Which Docker networking driver allows containers on the same host to communicate using container names?
- bridge (Correct answer)
- host
- none
- overlay
Correct answer: bridge
The bridge network driver creates a private internal network on the host and enables containers connected to the same bridge to communicate by name.
Question 6: What does the EXPOSE instruction in a Dockerfile do?
- Documents which port the container listens on at runtime (Correct answer)
- Automatically publishes the port to the host machine
- Opens a firewall rule for the specified port
- Maps the container port to a host port
Correct answer: Documents which port the container listens on at runtime
EXPOSE is documentation that informs Docker and users which port the container application listens on; it does not automatically publish the port to the host.
What is a Docker image?