Challenge your understanding of key Docker concepts with this quiz, designed to help you review containerization basics, networking, storage, and orchestration. Enhance your Docker interview preparation with realistic questions focused on practical and theoretical aspects of using Docker.
Which statement best describes the purpose of a Docker image in the containerization process?
Explanation: A Docker image serves as a read-only template from which containers are instantiated, containing application code, libraries, and environment settings. Unlike a standalone executable, an image cannot be directly run; it must be used to start a container. Containers, not images, generate runtime logs. Docker images are not the same as virtual machine snapshots, as they do not contain full operating systems.
If you need data generated by a Docker container to persist even after the container is removed, which Docker feature should you use?
Explanation: Docker volumes are specifically designed to store persistent data independent of the container’s lifecycle. They allow information to be retained even if the container is deleted or recreated. Docker layers are part of the image build process and don't preserve data at runtime, Compose files are for orchestrating multi-container setups and do not handle persistence, and tags are used for image versioning, not data storage.
In Docker, what is the primary purpose of the 'bridge' network mode when launching containers?
Explanation: The 'bridge' network mode creates a private virtual network on the host, allowing containers to communicate securely with each other while remaining isolated from the outside unless ports are mapped. Allowing all ports to be open would pose security risks and is not the function of bridge mode. Direct hardware interface access and encrypted cross-host tunneling are provided by different configurations and are not part of the 'bridge' network’s primary purpose.
Which Dockerfile instruction is used to specify a command that should run by default when a container starts?
Explanation: CMD defines the default command to run when a container starts, unless overridden at runtime. RUN executes commands while building the image, not at container start. COPY is used to transfer files and directories into the image. EXPOSE is a way to document which network ports the container will listen on, but does not specify which command to execute.
When managing multiple Docker containers as a group with scaling and self-healing, which concept or tool is commonly employed?
Explanation: Orchestration involves coordinating and managing clusters of containers, allowing for automatic scaling, load balancing, and recovery from failures. Linking is an older method of connecting containers and does not provide group management. Tagging is used for versioning images and has no effect on container coordination. Port mapping is related to network configuration, not container management or scaling.