programming
beginner
10 sample questions
Containerization MCQ Practice Test
Using Docker to package applications with all dependencies.
Managing containerized apps on cloud platforms.
Q1. You're using Kubernetes to orchestrate your microservices. One service, responsible for image processing, is being restarted repeatedly, and kubectl events show numerous 'OOMKilled' events for its pods. Which is the MOST effective initial troubleshooting step?
-
A. Increase the number of replicas for the image processing service
-
B. Review the pod's memory usage and adjust its memory requests and limits (and check for leaks) ✓
-
C. Upgrade the underlying Kubernetes nodes to larger instance sizes
-
D. Implement a custom resource quota limiting total memory usage across all namespaces
Explanation: OOMKilled means the container exceeded its memory limit and the kernel killed it. The first response is to inspect actual memory usage (metrics, profiling, possible leaks) and correct the memory requests/limits - or fix the leak. Adding replicas just multiplies dying pods, node upgrades are a costly last resort, and resource quotas are cluster-wide governance, not a fix for one service.
Q2. You're using Docker Compose to orchestrate a multi-container application. One service depends on a database service. The database service's startup is unexpectedly slow, causing the dependent service to fail its health check before the database is fully operational. Which Docker Compose configuration adjustment would BEST mitigate this issue?
-
A. Add a 'depends_on' entry with condition: service_healthy, and define a healthcheck for the database service ✓
-
B. Increase the number of replicas for the database service using the 'deploy' section
-
C. Set a longer timeout value for the dependent service's health check in the Dockerfile
-
D. Use Docker Swarm to manage the services, leveraging its built-in service discovery and load balancing
Explanation: Compose's depends_on with condition: service_healthy waits until the database container reports healthy (via its healthcheck) before starting the dependent service - this directly fixes the readiness-ordering failure. Plain depends_on (start order only) doesn't wait for readiness; healthcheck timeouts live in compose files, not the Dockerfile, and don't fix ordering; replicas and Swarm don't address the timing problem.
Q3. What is the primary purpose of the "docker build" command in containerization?
-
A. To create a new Docker image from a Dockerfile ✓
-
B. To run a Docker container from an existing image
-
C. To push a Docker image to a container registry
-
D. To pull a Docker image from a container registry
Explanation: The "docker build" command is used to create a new Docker image from a Dockerfile, which defines the instructions for building the image. This command is essential in containerization as it allows developers to package their applications and dependencies into a single container that can be easily deployed and managed.
Q4. What is the primary purpose of the .dockerignore file in a Docker containerization project?
-
A. To specify the Docker image to be used for the project
-
B. To exclude files and directories from being included in the Docker image ✓
-
C. To set environment variables for the Docker container
-
D. To configure the Docker container's networking settings
Explanation: The .dockerignore file is used to specify files and directories that should not be included in the Docker image, improving build performance and reducing image size.
Q5. In a Docker Compose file, what is the correct syntax to define a container that uses the latest version of an image from Docker Hub?
-
A. image: latest:nginx
-
B. image: nginx:latest ✓
-
C. image: 'nginx:latest'
-
D. image: 'latest:nginx'
Explanation: In a Docker Compose file, the correct syntax to define a container that uses the latest version of an image from Docker Hub is to use the format image: repository:tag, where repository is the name of the image and tag is the version. The correct syntax is image: nginx:latest, where nginx is the repository and latest is the tag.
Q6. Which of the following Dockerfile instructions is used to expose a container port for external access?
-
A. FROM instruction
-
B. RUN instruction
-
C. EXPOSE instruction ✓
-
D. CMD instruction
Explanation: The EXPOSE instruction in a Dockerfile is used to inform Docker which port to map from the container to the host during the container creation process. This allows external access to the container.
Q7. Which of the following Dockerfile instructions is used to expose a port in a Docker container?
-
A. FROM instruction
-
B. WORKDIR instruction
-
C. EXPOSE instruction ✓
-
D. COPY instruction
Explanation: The EXPOSE instruction in a Dockerfile is used to inform the port that a container will listen on. It does not actually open the port, but rather informs the user and the Docker daemon about the port.
Q8. Which of the following Dockerfile instructions is used to set the working directory in a Docker container?
-
A. FROM instruction
-
B. RUN instruction
-
C. WORKDIR instruction ✓
-
D. COPY instruction
Explanation: The WORKDIR instruction sets the working directory in a Docker container. It is used to change the current working directory in the container to the specified path.
Q9. In Docker, what is the primary purpose of a Dockerfile?
-
A. To define the environment variables for a container
-
B. To specify the base image and instructions for building a Docker image ✓
-
C. To configure the networking settings for a container
-
D. To manage the container's lifecycle
Explanation: A Dockerfile is a text file that contains a set of instructions for building a Docker image. It specifies the base image, copies files into the image, sets environment variables, and more.
Q10. What is the primary benefit of using Dockerfiles in containerization?
-
A. Reducing the size of container images
-
B. Improving the security of container images
-
C. Simplifying the process of building and deploying applications ✓
-
D. Increasing the complexity of container orchestration
Explanation: Dockerfiles are a text-based format for defining the instructions for building a Docker image. They allow developers to automate the process of building and deploying their applications, making it easier to manage and maintain their codebase.
That was just a sample. Sign up to unlock the full question bank with timed tests and certificates.
Sign Up Free