Written by Ashmit N. Rai • Co-Founder & DevOps Platform EngineerDevOps specialist and platform automation architect. Expert in containerization.
Interactive Flashcards
# 1
Unreviewed
What is the difference between CMD and ENTRYPOINT in a Dockerfile?
Answer Guide
ENTRYPOINT configures the default executable command that will run when the container starts. CMD specifies default arguments passed to the ENTRYPOINT (or the entire executable if ENTRYPOINT is not set). Arguments passed to "docker run <image> <args>" will overwrite CMD entirely, but will be appended to ENTRYPOINT.
Key Concepts Checklist
Evaluate difficulty:
# 2
Unreviewed
What is a multi-stage build, and how does it optimize Docker images?
Answer Guide
Multi-stage builds use multiple "FROM" instructions in a single Dockerfile. Developers can compile/build applications in a heavy build stage (with SDKs and dev dependencies) and then "COPY" only the compiled binary/assets into a separate, minimal run stage (e.g., Alpine or Distroless), significantly reducing image size.
Key Concepts Checklist
Evaluate difficulty:
# 3
Unreviewed
What is the difference between Docker Volumes and Bind Mounts?
Answer Guide
Docker Volumes are managed entirely by Docker, stored in a private directory on the host machine (/var/lib/docker/volumes/), and are independent of the host directory structure. Bind Mounts link a specific host path directly to a container path, making them dependent on the host OS file structure (commonly used for local code sharing during development).
Key Concepts Checklist
Evaluate difficulty:
# 4
Unreviewed
What command do you use to access a running Docker container's shell?
Answer Guide
Use the command "docker exec -it <container_id_or_name> /bin/bash" (or "/bin/sh" if bash is not available). The "-i" flag keeps stdin open, and "-t" allocates a pseudo-TTY for interactive terminal input.
Key Concepts Checklist
Evaluate difficulty:
# 5
Unreviewed
What is the difference between COPY and ADD instructions in a Dockerfile?
Answer Guide
"COPY" only supports copying local files/directories from the host build context to the container destination. "ADD" has additional capabilities: it can download files from remote URLs and automatically extract local compressed tar files into the target container directory.
Key Concepts Checklist
Evaluate difficulty:
# 6
Unreviewed
How do you view logs from a container that has crashed or is currently running?
Answer Guide
Run "docker logs <container_id_or_name>". You can use the "--follow" (or "-f") flag to stream logs in real-time, or "--tail <N>" to view only the last N lines.
Key Concepts Checklist
Evaluate difficulty:
# 7
Unreviewed
How does Docker's layering system work, and how can you leverage it for faster builds?
Answer Guide
Docker images are built as a series of read-only layers. Each instruction in a Dockerfile (like RUN, COPY, ADD) creates a new layer. To optimize build caching, place instructions that change frequently (like "COPY . .") at the bottom of the Dockerfile, and instructions that rarely change (like installing dependencies) at the top.
Key Concepts Checklist
Evaluate difficulty:
# 8
Unreviewed
How do you list running containers vs all (including stopped) containers?
Answer Guide
Run "docker ps" to list only running containers. Run "docker ps -a" (or "docker ps --all") to list all containers, showing their exit codes and termination times.
Key Concepts Checklist
Evaluate difficulty:
# 9
Unreviewed
How do you expose a port when running a Docker container?
Answer Guide
Use the "-p" (or "--publish") flag during "docker run". The syntax is "docker run -p <host_port>:<container_port> <image>". This maps traffic from the host machine's port to the container's internal port.
Key Concepts Checklist
Evaluate difficulty:
# 10
Unreviewed
What is Docker Compose, and what is its purpose?
Answer Guide
Docker Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file (docker-compose.yml) to configure the application's services, networks, volumes, and environment variables, allowing the entire stack to be launched with a single command: "docker-compose up".
Key Concepts Checklist
Evaluate difficulty:
# 11
Unreviewed
How do you write a Dockerfile for a Node.js application?
Answer Guide
Specify a base image ("FROM node:alpine"), set the working directory ("WORKDIR /usr/src/app"), copy dependency locks ("COPY package*.json ./"), install dependencies ("RUN npm install"), copy the application source ("COPY . ."), expose the port ("EXPOSE 3000"), and run the start command ("CMD ["npm", "start"]").
Key Concepts Checklist
Evaluate difficulty:
# 12
Unreviewed
What is the architecture of Docker?
Answer Guide
Docker uses a client-server architecture. The Docker Client (command-line tool) communicates with the Docker Daemon (dockerd), which does the heavy lifting of building, running, and distributing your containers. The Daemon can fetch images from Docker Registries (like Docker Hub or ECR) and manages local host system container resources.
Key Concepts Checklist
Evaluate difficulty:
Scenario Challenges
Select a scenario below to test your troubleshooting workflow.
Topic: Image Size Optimization
Optimize a heavy Node.js image that currently takes 1.2GB of disk space down to under 150MB. Arrange the steps.
Select node:alpine or node:slim as the base image instead of node:latest.Click to select
Create a .dockerignore file to exclude local node_modules, git assets, and test logs.Click to select
Implement a multi-stage Dockerfile to run build steps and copy only node_modules/prod directories.Click to select
Selected Sequence
No steps selected yet. Click options above in sequence.
Topic: Container Data Persistence
Ensure Postgres database data is not lost when its container is stopped, restarted, or deleted. Order the setup.
Create a named Docker volume managed by the daemon: docker volume create pg-data.Click to select
Run the Postgres container mapping the volume path: -v pg-data:/var/lib/postgresql/data.Click to select
Verify container deletes do not affect the persistent volume mount in /var/lib/docker/volumes.Click to select
Selected Sequence
No steps selected yet. Click options above in sequence.
Topic: Port Conflict Resolution
A new Nginx container fails to launch due to port 80 allocation conflict on the host system. Resolve the collision.
Find the PID occupying port 80 using lsof -i :80 or netstat -tuln | grep 80.Click to select
Stop the conflicting process or determine a non-conflicting host port (e.g., 8080).Click to select
Start the container mapping to the free port: docker run -d -p 8080:80 nginx.Click to select
Selected Sequence
No steps selected yet. Click options above in sequence.
Topic: Custom Bridge Networking
Connect a Node web container and a Redis container so they can communicate using hostnames, avoiding hardcoded IPs.
Create a custom Docker network: docker network create app-bridge.Click to select
Launch both web and Redis containers attaching them to app-bridge.Click to select
Configure the web app connection string to use the Redis container name "redis" as the hostname.Click to select
Selected Sequence
No steps selected yet. Click options above in sequence.
Topic: Docker Compose Deployment
Deploy a multi-tier database-backend-frontend application using Docker Compose with correct startup order.
Define all services, variables, and network configurations inside docker-compose.yml.Click to select
Configure depends_on and container healthchecks to enforce the database starting first.Click to select
Execute docker-compose up -d to orchestrate the entire multi-container stack.Click to select
Selected Sequence
No steps selected yet. Click options above in sequence.
We value your privacy
We use cookies to analyze site traffic, personalize content, and support our free educational platforms. By clicking "Accept All", you consent to our use of cookies.