Discover how Docker tackles the 'it works on my machine' issue, the differences between containers and images, and key commands for streamlined app delivery. This quiz covers practical concepts, analogies, and best practices from a beginner-friendly Docker guide.
What is the main cause of software behaving differently on different machines?
Explanation: Environment drift means differences in libraries, environment variables, or OS configurations between systems, which leads to unexpected app behavior. Outdated syntax and incorrect language usually cause errors regardless of environment. Slow internet may affect downloads but not core code execution differences.
Which analogy best explains how Docker packages applications for consistent results?
Explanation: Docker packages everything needed, like a sealed pod containing all ingredients and tools. Sending a recipe or using random ingredients leads to inconsistencies. Borrowing a cookbook doesn't ensure the same tools or environment.
Which is a key difference between virtual machines (VMs) and Docker containers?
Explanation: Containers leverage the host OS and avoid full OS configs, making them lighter. VMs are heavier, emulate hardware, and require full OS setups. VMs do not run on container runtimes but use hypervisors.
What is the primary difference between a Docker image and a Docker container?
Explanation: A Docker image is a static collection of code and configuration, like a recipe, while the container is the actual running instance. The other options are incorrect or misleading about the nature of images and containers.
Which single Docker command both creates and starts a container, then shows its output?
Explanation: The docker run command combines creation, starting, and output display in one step. docker ps shows running containers, docker logs only displays logs, and docker container create only prepares (but does not run) the container.
What is the purpose of using the '-d' flag with 'docker run'?
Explanation: The '-d' flag (detached mode) allows the container to run without blocking the terminal. It does not delete anything, show logs directly, or allocate extra memory by default.
What does the command 'docker run -p 8080:5000' do?
Explanation: This command allows outside access through host port 8080, forwarding to the container's port 5000. The second option reverses the mapping, which is incorrect. The other options are unrelated to port mapping.
Which command should be used to remove a Docker container after stopping it?
Explanation: docker rm removes a stopped container, freeing up space. docker ps lists containers, docker rmi removes images, and docker logs displays output from containers but does not delete anything.