Docker Interview Master
The ultimate collection of 200+ meticulously curated Docker & Containerization questions to help you ace your DevOps interview.
What is Docker?
BeginnerDocker is an open-source platform that enables developers to build, deploy, run, update and manage containers. It standardizes software delivery by isolating ap...
Comprehensive Explanation
What is a Docker Container?
BeginnerA container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing enviro...
Comprehensive Explanation
What is a Docker Image?
BeginnerA Docker image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, ...
Comprehensive Explanation
What is the difference between an Image and a Container?
BeginnerAn image is a read-only template with instructions for creating a container. A container is a runnable, working instance of an image.
Comprehensive Explanation
What is Docker Engine?
BeginnerDocker Engine is the core client-server application that builds and runs containers using Docker components. It consists of a server daemon running in the backg...
Comprehensive Explanation
What is Docker Hub?
BeginnerDocker Hub is a cloud-based registry service provided by Docker that allows you to link to code repositories, build your images, and test them, store manually p...
Comprehensive Explanation
Explain Docker Architecture.
BeginnerDocker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your...
Comprehensive Explanation
What is a Dockerfile?
BeginnerA Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build, you can create an...
Comprehensive Explanation
What is Docker Compose?
BeginnerDocker Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file to configure application services, networks, and volu...
Comprehensive Explanation
What is the command to run a container?
BeginnerThe `docker run` command is used to run a container from an image.
Comprehensive Explanation
Command / Code
docker run -d -p 8080:80 nginxHow do you check running containers?
BeginnerYou can check running containers using the `docker ps` command.
Comprehensive Explanation
Command / Code
docker psHow do you check all containers (running and stopped)?
BeginnerUse `docker ps -a` to view all containers, regardless of their current state.
Comprehensive Explanation
Command / Code
docker ps -aHow do you stop a running container?
BeginnerUse the `docker stop` command followed by the container ID or name.
Comprehensive Explanation
Command / Code
docker stop <container_id_or_name>How do you remove a stopped container?
BeginnerUse the `docker rm` command followed by the container ID or name.
Comprehensive Explanation
Command / Code
docker rm <container_id_or_name>How do you remove a Docker image?
BeginnerUse the `docker rmi` command followed by the image ID or name.
Comprehensive Explanation
Command / Code
docker rmi <image_id_or_name>What is the command to list all images?
BeginnerUse the `docker images` or `docker image ls` command to list all locally available Docker images.
Comprehensive Explanation
Command / Code
docker imagesHow do you pull an image from Docker Hub?
BeginnerUse the `docker pull` command followed by the image name.
Comprehensive Explanation
Command / Code
docker pull ubuntu:latestWhat is Docker Swarm?
BeginnerDocker Swarm is a clustering and scheduling tool for Docker containers. It allows you to manage multiple containers deployed across multiple host machines as a ...
Comprehensive Explanation
What is the difference between Virtual Machines and Docker Containers?
BeginnerVMs run a full guest operating system with virtual access to host resources. Docker containers share the host's OS kernel, making them much more lightweight, fa...
Comprehensive Explanation
What is a Docker Volume?
BeginnerA volume is a persistent data storage mechanism used to persist data generated by and used by Docker containers, completely managed by Docker.
Comprehensive Explanation
What does the `FROM` instruction do in a Dockerfile?
BeginnerThe `FROM` instruction initializes a new build stage and sets the Base Image for subsequent instructions. It must be the first valid instruction in a Dockerfile...
Comprehensive Explanation
What does the `RUN` instruction do?
BeginnerThe `RUN` instruction executes any commands in a new layer on top of the current image and commits the results. The resulting image is used for the next step.
Comprehensive Explanation
What is the `docker build` command used for?
BeginnerThe `docker build` command builds Docker images from a Dockerfile and a context (a specific directory or URL).
Comprehensive Explanation
Command / Code
docker build -t myapp:1.0 .How do you map a port from host to container?
BeginnerUse the `-p` or `--publish` flag with `docker run` to map a host port to a container port.
Comprehensive Explanation
Command / Code
docker run -p 8080:80 myimageWhat is the `docker exec` command used for?
BeginnerThe `docker exec` command allows you to run a new command in an already running container. Often used to open an interactive shell.
Comprehensive Explanation
Command / Code
docker exec -it <container_id> /bin/bashExplain the difference between CMD and ENTRYPOINT in a Dockerfile.
Intermediate`ENTRYPOINT` configures a container that will run as an executable. `CMD` provides default arguments for an executing container. If used together, CMD arguments...
Comprehensive Explanation
What are Docker Namespaces?
IntermediateNamespaces provide the isolation for Docker containers. When you run a container, Docker creates a set of namespaces for it (PID, NET, IPC, MNT, UTS), restricti...
Comprehensive Explanation
What are Docker Control Groups (cgroups)?
IntermediateControl groups limit and isolate the resource usage (CPU, memory, disk I/O, network) of a collection of processes. Docker uses cgroups to allocate hardware reso...
Comprehensive Explanation
What is the difference between `COPY` and `ADD` in a Dockerfile?
Intermediate`COPY` only supports the basic copying of local files into the container. `ADD` has additional features like extracting local tar files and downloading files fr...
Comprehensive Explanation
How does Docker handle networking by default?
IntermediateDocker provides three default network drivers: `bridge` (default for standalone containers), `host` (container shares the host's networking), and `none` (no net...
Comprehensive Explanation
What is a Bridge Network in Docker?
IntermediateA bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers n...
Comprehensive Explanation
How can you pass environment variables to a Docker container?
IntermediateYou can pass environment variables using the `-e` flag during `docker run` or by defining them in a `.env` file or `docker-compose.yml`.
Comprehensive Explanation
Command / Code
docker run -e MY_VAR=value myimageWhat is the purpose of `.dockerignore` file?
IntermediateThe `.dockerignore` file allows you to specify files and directories that should be excluded from the build context sent to the Docker daemon. This speeds up th...
Comprehensive Explanation
How do you scale services with Docker Compose?
IntermediateYou can use the `--scale` flag when running `docker-compose up` to run multiple instances of a specific service.
Comprehensive Explanation
Command / Code
docker-compose up --scale web=3 -dWhat is dangling image and how to remove them?
IntermediateDangling images are layers that have no relationship to any tagged images (shown as <none>). You remove them using `docker image prune`.
Comprehensive Explanation
Command / Code
docker image prune -fExplain Bind Mounts vs Volumes.
IntermediateBind mounts map a specific absolute path on the host to the container. Volumes are completely managed by Docker and stored in a specific host directory. Volumes...
Comprehensive Explanation
What does the `EXPOSE` instruction do?
Intermediate`EXPOSE` functions as documentation between the person who builds the image and the person who runs the container, declaring which ports the container will list...
Comprehensive Explanation
How do you view logs of a Docker container?
IntermediateUse the `docker logs` command followed by the container ID or name to view stdout/stderr output.
Comprehensive Explanation
Command / Code
docker logs -f <container_name>What is a multi-stage Docker build?
IntermediateMulti-stage builds allow you to use multiple `FROM` statements in a Dockerfile. You can selectively copy artifacts from one stage to another, leaving behind eve...
Comprehensive Explanation
How do you execute a command within a running container?
IntermediateUse `docker exec` to start a new process in a running container.
Comprehensive Explanation
Command / Code
docker exec -it <container_name> ls -lah /appWhat happens to data when a container exits?
IntermediateData stored in the container's writable layer persists when the container stops but is lost if the container is removed. Volumes should be used for persistent d...
Comprehensive Explanation
What are Docker Labels?
IntermediateLabels are a mechanism to apply metadata to Docker objects, including images, containers, local daemons, volumes, and networks.
Comprehensive Explanation
How do you restart a Docker container automatically if it crashes?
IntermediateUse restart policies like `--restart=always`, `--restart=on-failure`, or `--restart=unless-stopped` when running the container.
Comprehensive Explanation
Command / Code
docker run -d --restart always nginxWhat is `docker system prune`?
IntermediateThis command deletes all stopped containers, unused networks, dangling images, and build cache to free up disk space.
Comprehensive Explanation
Command / Code
docker system prune -a --volumesHow can a container communicate with the host machine?
IntermediateFrom Docker 18.03 onwards, containers can use `host.docker.internal` (on Mac/Windows) to resolve to the host machine's internal IP address.
Comprehensive Explanation
What is overlay network in Docker?
IntermediateAn overlay network connects multiple Docker daemons together and enables swarm services or standalone containers to communicate securely across different networ...
Comprehensive Explanation
What is difference between `docker start` and `docker run`?
Intermediate`docker run` creates a *new* container from an image and starts it. `docker start` simply starts an *existing* stopped container without recreating it.
Comprehensive Explanation
How to specify a custom Dockerfile name when building an image?
IntermediateUse the `-f` or `--file` flag during the `docker build` process.
Comprehensive Explanation
Command / Code
docker build -f Dockerfile.prod -t myapp:prod .What is a dangling volume and how to clean it?
IntermediateA dangling volume is a volume not attached to any container. They can be cleaned up using `docker volume prune`.
Comprehensive Explanation
How to inspect detailed configuration of a container?
IntermediateUse the `docker inspect` command to return low-level information on Docker objects in JSON format.
Comprehensive Explanation
Command / Code
docker inspect <container_id>How does Docker caching work during `docker build`?
AdvancedDocker steps through instructions in the Dockerfile, executing each. For each step, it checks its cache for an existing image resulting from the same base image...
Comprehensive Explanation
Why should you minimize the number of layers in a Docker image?
AdvancedEach `RUN`, `COPY`, and `ADD` instruction creates a new layer, which increases the overall image size and build/push/pull time. Combining multiple commands usin...
Comprehensive Explanation
Explain User Namespace Remapping in Docker.
AdvancedUser namespace remapping allows you to map the root user inside a container to a non-root user on the host. This mitigates the risk of a container breakout wher...
Comprehensive Explanation
What is Docker Storage Driver?
AdvancedStorage drivers control how images and containers are stored and managed on your Docker host. They use a union filesystem (like overlay2, btrfs, zfs). `overlay2...
Comprehensive Explanation
How do you manage secrets in Docker Compose?
AdvancedDocker Compose allows defining secrets using the `secrets` top-level block. These secrets are mounted as files in `/run/secrets/` inside the container, avoiding...
Comprehensive Explanation
How do you handle graceful shutdowns of Docker containers?
AdvancedContainers should handle `SIGTERM` signals correctly. By default, `docker stop` sends `SIGTERM`, waits 10s, and then sends `SIGKILL`. Your app must handle `SIGT...
Comprehensive Explanation
What is a Node in Docker Swarm?
AdvancedA node is an instance of the Docker engine participating in the swarm. You have Manager nodes (which orchestrate and manage cluster state) and Worker nodes (whi...
Comprehensive Explanation
How do you backup, restore, or migrate data volumes?
AdvancedRun a temporary container, mount the data volume, and mount a host directory. Then use `tar` to archive the contents of the data volume to the host directory. R...
Comprehensive Explanation
What are Docker Content Trust (DCT) and Image Signing?
AdvancedDCT gives you the ability to use digital signatures for data sent to and received from remote Docker registries. It ensures image integrity, allowing the docker...
Comprehensive Explanation
How can you speed up CI/CD pipeline Docker builds?
AdvancedUtilize `--cache-from` to use pre-built images as cache sources. Use Docker Buildkit (`DOCKER_BUILDKIT=1`) for parallel execution and better caching. Maximize c...
Comprehensive Explanation
What is Docker BuildKit?
AdvancedBuildKit is an improved build backend designed to be more efficient, cache-friendly, and secure. Features include concurrent build steps, skipping unused stages...
Comprehensive Explanation
Explain the `HEALTHCHECK` instruction.
Advanced`HEALTHCHECK` tells Docker how to test a container to check that it is still working. This allows detecting cases such as a web server that is stuck in an infin...
Comprehensive Explanation
How do you limit CPU and Memory for a container?
AdvancedUse flags like `--cpus` and `-m` or `--memory` during `docker run` to restrict resources using namespaces/cgroups.
Comprehensive Explanation
Command / Code
docker run -it --cpus=".5" --memory="256m" ubuntu /bin/bashWhat is a Zombie Process in a container and how do you prevent it?
AdvancedZombie processes remain in the system's process table after terminating because the parent process hasn't read their exit status. Use an init process like `tini...
Comprehensive Explanation
How do you configure a container to use a specific DNS server?
AdvancedPass the `--dns` flag to `docker run` to override the default DNS resolution settings.
Comprehensive Explanation
Command / Code
docker run -d --dns 8.8.8.8 nginxWhat is `scratch` image in Docker?
Advanced`scratch` is an explicitly empty image, mainly used as a base for completely self-contained statically linked binaries (like Go applications), producing the sma...
Comprehensive Explanation
Explain what `docker context` is.
AdvancedDocker contexts allow you to easily manage multiple environments (like local Docker, remote servers, Kubernetes) and switch between them seamlessly using `docke...
Comprehensive Explanation
How do you troubleshoot a container that immediately exits?
AdvancedCheck the exit code and logs (`docker logs`). Often the main process exited because of an error, or the `ENTRYPOINT/CMD` script completed its execution (e.g. `C...
Comprehensive Explanation
What is the difference between `docker-compose up` and `docker-compose run`?
Advanced`docker-compose up` builds, (re)creates, starts, and attaches to all containers. `docker-compose run` creates and starts a one-off container for a specific serv...
Comprehensive Explanation
How to use `docker wait`?
Advanced`docker wait` blocks until one or more containers stop, then prints their exit codes. Useful for CI/CD scripting.
Comprehensive Explanation
What is Macvlan network in Docker?
AdvancedMacvlan allows you to assign a MAC address to a container, making it appear as a physical device on your network. Useful for legacy applications that expect to ...
Comprehensive Explanation
How does the `ARG` instruction differ from `ENV`?
Advanced`ARG` variables are only available during the `docker build` process and are not passed fully into the final image. `ENV` variables persist and are available du...
Comprehensive Explanation
What is Docker's Copy-on-Write (CoW) strategy?
AdvancedDocker uses CoW for image layers. When an existing file in a lower read-only layer is modified by a container, Docker copies the file up to the container's writ...
Comprehensive Explanation
How to log container output to an external system?
AdvancedBy using Docker logging drivers. You can configure logging drivers like `json-file` (default), `syslog`, `fluentd`, `awslogs`, or `splunk` either at the daemon ...
Comprehensive Explanation
What is the `ONBUILD` instruction used for?
Advanced`ONBUILD` adds a trigger instruction to an image that will be executed later, when the image is used as the base for another build. Useful for building language...
Comprehensive Explanation
You forgot your container's internal IP. How do you find it?
ScenarioInspect the specific container and filter for the IP address.
Comprehensive Explanation
Command / Code
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_id_or_name>Your host is out of space. You want to remove ALL unused Docker data (containers, networks, images, and volumes).
ScenarioUse `docker system prune` with the `-a` and `--volumes` flags.
Comprehensive Explanation
Command / Code
docker system prune -a --volumes -fHow do you enter a bash shell of a running Alpine Linux container to debug?
ScenarioAlpine Linux typically uses `sh` instead of `bash`. Use `docker exec`.
Comprehensive Explanation
Command / Code
docker exec -it <container_name> /bin/shYou want to build a Dockerfile named `build.docker` in the `src` directory.
ScenarioUse the `-f` flag to point to the specific file, and set the correct build context.
Comprehensive Explanation
Command / Code
docker build -f src/build.docker -t myapp src/How do you copy a log file from a container to your host machine?
ScenarioUse the `docker cp` command.
Comprehensive Explanation
Command / Code
docker cp mycontainer:/var/log/app.log ./app.logHow do you force stop a frozen container without waiting 10 seconds?
ScenarioUse `docker kill`, which immediately sends a `SIGKILL` instead of the graceful `SIGTERM`.
Comprehensive Explanation
Command / Code
docker kill <container_name>Your database container failed to start. How do you check what happened in the last 20 log lines?
ScenarioUse `docker logs` with the `--tail` flag.
Comprehensive Explanation
Command / Code
docker logs --tail 20 <container_name>How do you start a container, execute an ephemeral command, and ensure it deletion automatically afterwards?
ScenarioUse the `--rm` flag with `docker run`.
Comprehensive Explanation
Command / Code
docker run --rm ubuntu ls -lahHow do you restart all services defined in a docker-compose file while rebuilding their images?
ScenarioPass the `--build` flag to `docker-compose up`.
Comprehensive Explanation
Command / Code
docker-compose up -d --build --force-recreateYou need to export an image to a tarball file to transfer it via USB.
ScenarioUse the `docker save` command.
Comprehensive Explanation
Command / Code
docker save -o myimage.tar myimage:latestHow do you load the Docker image you just transferred via USB?
ScenarioUse the `docker load` command.
Comprehensive Explanation
Command / Code
docker load -i myimage.tarA container is consuming too much memory and freezing your host. How do you limit it dynamically?
ScenarioUse `docker update` on a running container.
Comprehensive Explanation
Command / Code
docker update -m 512m <container_name>How do you display real-time resource usage statistics for all running containers?
ScenarioUse the `docker stats` command.
Comprehensive Explanation
Command / Code
docker statsYou want to run a Redis container interactively, testing a few commands, then exit without leaving the container behind.
ScenarioRun it with `--rm` and `-it`.
Comprehensive Explanation
Command / Code
docker run -it --rm redis redis-cliYou modified a file locally in your React app. How do you see the changes immediately in the Dockerized app without rebuilding?
ScenarioUse a bind volume mount mapping your local directory to the container directory.
Comprehensive Explanation
Command / Code
docker run -v $(pwd)/src:/app/src -p 3000:3000 myreactappHow do you see all environment variables available inside a running container?
ScenarioUse `docker exec` to run the `env` command.
Comprehensive Explanation
Command / Code
docker exec <container_name> envHow do you inspect the differences between the container's writable layer and the base image?
ScenarioUse the `docker diff` command. It lists altered, added, and deleted files.
Comprehensive Explanation
Command / Code
docker diff <container_name>How do you commit a container's file changes into a new image?
ScenarioUse the `docker commit` command.
Comprehensive Explanation
Command / Code
docker commit <container_name> mynewimage:v1How do you see the intermediate layers that make up a Docker image?
ScenarioUse the `docker history` command.
Comprehensive Explanation
Command / Code
docker history myimage:latestHow to quickly fetch only the IDs of all running containers?
ScenarioUse `docker ps` with the `-q` (quiet) flag.
Comprehensive Explanation
Command / Code
docker ps -qHow do you stop all running containers using a single command?
ScenarioPass the output of `docker ps -q` to `docker stop`.
Comprehensive Explanation
Command / Code
docker stop $(docker ps -q)Your `.env` file requires specific parsing for Docker Compose. How do you verify the compiled compose file before running it?
ScenarioUse the `docker-compose config` command to validate and view the complete configuration.
Comprehensive Explanation
Command / Code
docker-compose configIn swarm mode, how do you see all tasks/containers running for a specific service?
ScenarioUse the `docker service ps` command.
Comprehensive Explanation
Command / Code
docker service ps <service_name>How to mount the docker socket into a container so the container can start other containers?
ScenarioBind mount `/var/run/docker.sock`. (Note: This has massive security implications).
Comprehensive Explanation
Command / Code
docker run -v /var/run/docker.sock:/var/run/docker.sock myimageHow do you format output of `docker ps` to only show the container name and its status?
ScenarioUse the `--format` flag with Go templates.
Comprehensive Explanation
Command / Code
docker ps --format "{{.Names}}: {{.Status}}"