Docker Multiple-Choice Questions
1. Why is Docker useful in software development?
A) It eliminates the need for a server
B) It creates a standardized environment across different machines
C) It replaces the need for Python
D) It automatically fixes application crashes
2. How does Docker differ from a Virtual Machine?
A) Docker runs on a separate operating system while VMs share the host OS
B) Docker containers take up more space than VMs
C) Docker uses containers within an existing OS, whereas VMs simulate a whole OS
D) Docker requires cloud services, but VMs do not
3. What is the purpose of a Dockerfile
?
A) To define how to run Docker containers
B) To store environment variables
C) To manage Docker networking
D) To configure system hardware
4. In the provided Dockerfile
, what does FROM python:3
do?
A) Creates a new Python package
B) Specifies that the container is running Python 3
C) Installs Python 3 from a local file
D) Runs a Python script
5. What does the CMD
instruction in a Dockerfile
specify?
A) The base image to use
B) The command to run when the container starts
C) A list of environment variables
D) A list of dependencies to install
6. In the command COPY . /usr/src/app
, what does .
represent?
A) The container’s root directory
B) The current directory on the host machine
C) A wildcard for all files in the system
D) The Python package directory
7. What is the purpose of docker-compose.yml
?
A) To build and manage multiple containers together
B) To replace the need for a Dockerfile
C) To install dependencies within a container
D) To list all available containers on a machine
8. In docker-compose.yml
, what is the function of volumes
?
A) It stores logs generated by the container
B) It links directories between the host and the container
C) It specifies the network settings of the container
D) It determines the database version used
9. What does docker-compose up
do?
A) Builds and starts the services defined in docker-compose.yml
B) Deletes all running containers
C) Installs required dependencies in the container
D) Stops all running containers
10. What is the command to list all running Docker containers?
A) docker images
B) docker ps
C) docker start
D) docker ls
11. What does docker exec -it CONTAINER_ID bash -l
do?
A) Lists all running Docker containers
B) Enters the specified running container’s shell
C) Stops a running Docker container
D) Deletes a container
12. How do you exit an interactive session inside a Docker container?
A) docker stop
B) CTRL+C
C) CTRL+D
D) docker kill
Answers and Explanations
- B – Docker ensures that applications run in a consistent environment across different machines.
- C – Unlike VMs, Docker containers share the host OS kernel and consume fewer resources.
- A – A
Dockerfile
defines the setup and execution of a Docker container. - B – The
FROM
instruction selects a base image with Python 3 pre-installed. - B – The
CMD
command specifies what to run when the container starts. - B – The dot (
.
) represents the current working directory on the host machine. - A –
docker-compose.yml
helps define and manage multiple services (containers). - B –
volumes
link directories between the host and the container for persistent storage. - A –
docker-compose up
starts and builds services as defined indocker-compose.yml
. - B –
docker ps
lists all running Docker containers. - B – This command enters an interactive shell inside the specified container.
- C –
CTRL+D
exits an interactive shell session inside a Docker container.
Summary of Key Docker Concepts
- Purpose of Docker: Ensures applications run in a consistent environment across different systems.
- Containers vs. VMs: Containers share the host OS, making them lightweight; VMs run a full OS.
- Dockerfile: A script defining how a container should be built and run.
- Key Dockerfile Commands:
FROM
selects a base image.COPY
transfers files from the host to the container.WORKDIR
sets the working directory.RUN
executes setup commands.CMD
specifies the startup command.
- Docker Compose: Manages multiple containers, defined in
docker-compose.yml
. - Key Commands:
docker-compose up
: Starts all services.docker ps
: Lists running containers.docker exec -it CONTAINER_ID bash -l
: Enters a container shell.CTRL+D
: Exits a container session.