Docker Interview Master

The ultimate collection of 200+ meticulously curated Docker & Containerization questions to help you ace your DevOps interview.

0 / 200 LearnedCLI & ComposeNetworking & Orchestration
Showing 100 results in All Questions category.
1
What is Docker?
Beginner

Docker 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
Docker is an open-source platform that enables developers to build, deploy, run, update and manage containers. It standardizes software delivery by isolating applications in environments called containers.
Beginner
2
What is a Docker Container?
Beginner

A 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
A 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 environment to another.
Beginner
3
What is a Docker Image?
Beginner

A Docker image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, ...

Comprehensive Explanation
A Docker image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.
Beginner
4
What is the difference between an Image and a Container?
Beginner

An image is a read-only template with instructions for creating a container. A container is a runnable, working instance of an image.

Comprehensive Explanation
An image is a read-only template with instructions for creating a container. A container is a runnable, working instance of an image.
Beginner
5
What is Docker Engine?
Beginner

Docker 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
Docker Engine is the core client-server application that builds and runs containers using Docker components. It consists of a server daemon running in the background, a REST API, and a command-line interface (CLI).
Beginner
6
What is Docker Hub?
Beginner

Docker 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
Docker 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 pushed images, and links to Docker Cloud.
Beginner
7
Explain Docker Architecture.
Beginner

Docker 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
Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers.
Beginner
8
What is a Dockerfile?
Beginner

A 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
A 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 automated build.
Beginner
9
What is Docker Compose?
Beginner

Docker 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
Docker Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file to configure application services, networks, and volumes.
Beginner
10
What is the command to run a container?
Beginner

The `docker run` command is used to run a container from an image.

Comprehensive Explanation
The `docker run` command is used to run a container from an image.
Command / Code
docker run -d -p 8080:80 nginx
Beginner
11
How do you check running containers?
Beginner

You can check running containers using the `docker ps` command.

Comprehensive Explanation
You can check running containers using the `docker ps` command.
Command / Code
docker ps
Beginner
12
How do you check all containers (running and stopped)?
Beginner

Use `docker ps -a` to view all containers, regardless of their current state.

Comprehensive Explanation
Use `docker ps -a` to view all containers, regardless of their current state.
Command / Code
docker ps -a
Beginner
13
How do you stop a running container?
Beginner

Use the `docker stop` command followed by the container ID or name.

Comprehensive Explanation
Use the `docker stop` command followed by the container ID or name.
Command / Code
docker stop <container_id_or_name>
Beginner
14
How do you remove a stopped container?
Beginner

Use the `docker rm` command followed by the container ID or name.

Comprehensive Explanation
Use the `docker rm` command followed by the container ID or name.
Command / Code
docker rm <container_id_or_name>
Beginner
15
How do you remove a Docker image?
Beginner

Use the `docker rmi` command followed by the image ID or name.

Comprehensive Explanation
Use the `docker rmi` command followed by the image ID or name.
Command / Code
docker rmi <image_id_or_name>
Beginner
16
What is the command to list all images?
Beginner

Use the `docker images` or `docker image ls` command to list all locally available Docker images.

Comprehensive Explanation
Use the `docker images` or `docker image ls` command to list all locally available Docker images.
Command / Code
docker images
Beginner
17
How do you pull an image from Docker Hub?
Beginner

Use the `docker pull` command followed by the image name.

Comprehensive Explanation
Use the `docker pull` command followed by the image name.
Command / Code
docker pull ubuntu:latest
Beginner
18
What is Docker Swarm?
Beginner

Docker 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
Docker Swarm is a clustering and scheduling tool for Docker containers. It allows you to manage multiple containers deployed across multiple host machines as a single virtual system.
Beginner
19
What is the difference between Virtual Machines and Docker Containers?
Beginner

VMs 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
VMs 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, faster to start, and less resource-intensive.
Beginner
20
What is a Docker Volume?
Beginner

A volume is a persistent data storage mechanism used to persist data generated by and used by Docker containers, completely managed by Docker.

Comprehensive Explanation
A volume is a persistent data storage mechanism used to persist data generated by and used by Docker containers, completely managed by Docker.
Beginner
21
What does the `FROM` instruction do in a Dockerfile?
Beginner

The `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
The `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.
Beginner
22
What does the `RUN` instruction do?
Beginner

The `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
The `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.
Beginner
23
What is the `docker build` command used for?
Beginner

The `docker build` command builds Docker images from a Dockerfile and a context (a specific directory or URL).

Comprehensive Explanation
The `docker build` command builds Docker images from a Dockerfile and a context (a specific directory or URL).
Command / Code
docker build -t myapp:1.0 .
Beginner
24
How do you map a port from host to container?
Beginner

Use the `-p` or `--publish` flag with `docker run` to map a host port to a container port.

Comprehensive Explanation
Use the `-p` or `--publish` flag with `docker run` to map a host port to a container port.
Command / Code
docker run -p 8080:80 myimage
Beginner
25
What is the `docker exec` command used for?
Beginner

The `docker exec` command allows you to run a new command in an already running container. Often used to open an interactive shell.

Comprehensive Explanation
The `docker exec` command allows you to run a new command in an already running container. Often used to open an interactive shell.
Command / Code
docker exec -it <container_id> /bin/bash
Beginner
26
Explain 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
`ENTRYPOINT` configures a container that will run as an executable. `CMD` provides default arguments for an executing container. If used together, CMD arguments are appended to the ENTRYPOINT command.
Intermediate
27
What are Docker Namespaces?
Intermediate

Namespaces 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
Namespaces provide the isolation for Docker containers. When you run a container, Docker creates a set of namespaces for it (PID, NET, IPC, MNT, UTS), restricting what the container can see.
Intermediate
28
What are Docker Control Groups (cgroups)?
Intermediate

Control 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
Control groups limit and isolate the resource usage (CPU, memory, disk I/O, network) of a collection of processes. Docker uses cgroups to allocate hardware resources to containers.
Intermediate
29
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
`COPY` only supports the basic copying of local files into the container. `ADD` has additional features like extracting local tar files and downloading files from remote URLs.
Intermediate
30
How does Docker handle networking by default?
Intermediate

Docker provides three default network drivers: `bridge` (default for standalone containers), `host` (container shares the host's networking), and `none` (no net...

Comprehensive Explanation
Docker provides three default network drivers: `bridge` (default for standalone containers), `host` (container shares the host's networking), and `none` (no networking).
Intermediate
31
What is a Bridge Network in Docker?
Intermediate

A 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
A bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers not connected to it.
Intermediate
32
How can you pass environment variables to a Docker container?
Intermediate

You 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
You can pass environment variables using the `-e` flag during `docker run` or by defining them in a `.env` file or `docker-compose.yml`.
Command / Code
docker run -e MY_VAR=value myimage
Intermediate
33
What is the purpose of `.dockerignore` file?
Intermediate

The `.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
The `.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 the build and reduces image size.
Intermediate
34
How do you scale services with Docker Compose?
Intermediate

You can use the `--scale` flag when running `docker-compose up` to run multiple instances of a specific service.

Comprehensive Explanation
You can use the `--scale` flag when running `docker-compose up` to run multiple instances of a specific service.
Command / Code
docker-compose up --scale web=3 -d
Intermediate
35
What is dangling image and how to remove them?
Intermediate

Dangling images are layers that have no relationship to any tagged images (shown as <none>). You remove them using `docker image prune`.

Comprehensive Explanation
Dangling images are layers that have no relationship to any tagged images (shown as ). You remove them using `docker image prune`.
Command / Code
docker image prune -f
Intermediate
36
Explain Bind Mounts vs Volumes.
Intermediate

Bind 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
Bind 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 are preferred as they are easier to back up and isolate.
Intermediate
37
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
`EXPOSE` functions as documentation between the person who builds the image and the person who runs the container, declaring which ports the container will listen on. It does NOT literally publish the port.
Intermediate
38
How do you view logs of a Docker container?
Intermediate

Use the `docker logs` command followed by the container ID or name to view stdout/stderr output.

Comprehensive Explanation
Use the `docker logs` command followed by the container ID or name to view stdout/stderr output.
Command / Code
docker logs -f <container_name>
Intermediate
39
What is a multi-stage Docker build?
Intermediate

Multi-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
Multi-stage builds allow you to use multiple `FROM` statements in a Dockerfile. You can selectively copy artifacts from one stage to another, leaving behind everything you don't need, creating a smaller final image.
Intermediate
40
How do you execute a command within a running container?
Intermediate

Use `docker exec` to start a new process in a running container.

Comprehensive Explanation
Use `docker exec` to start a new process in a running container.
Command / Code
docker exec -it <container_name> ls -lah /app
Intermediate
41
What happens to data when a container exits?
Intermediate

Data 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
Data 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 data.
Intermediate
42
What are Docker Labels?
Intermediate

Labels are a mechanism to apply metadata to Docker objects, including images, containers, local daemons, volumes, and networks.

Comprehensive Explanation
Labels are a mechanism to apply metadata to Docker objects, including images, containers, local daemons, volumes, and networks.
Intermediate
43
How do you restart a Docker container automatically if it crashes?
Intermediate

Use restart policies like `--restart=always`, `--restart=on-failure`, or `--restart=unless-stopped` when running the container.

Comprehensive Explanation
Use restart policies like `--restart=always`, `--restart=on-failure`, or `--restart=unless-stopped` when running the container.
Command / Code
docker run -d --restart always nginx
Intermediate
44
What is `docker system prune`?
Intermediate

This command deletes all stopped containers, unused networks, dangling images, and build cache to free up disk space.

Comprehensive Explanation
This command deletes all stopped containers, unused networks, dangling images, and build cache to free up disk space.
Command / Code
docker system prune -a --volumes
Intermediate
45
How can a container communicate with the host machine?
Intermediate

From 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
From Docker 18.03 onwards, containers can use `host.docker.internal` (on Mac/Windows) to resolve to the host machine's internal IP address.
Intermediate
46
What is overlay network in Docker?
Intermediate

An overlay network connects multiple Docker daemons together and enables swarm services or standalone containers to communicate securely across different networ...

Comprehensive Explanation
An overlay network connects multiple Docker daemons together and enables swarm services or standalone containers to communicate securely across different network hosts.
Intermediate
47
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
`docker run` creates a *new* container from an image and starts it. `docker start` simply starts an *existing* stopped container without recreating it.
Intermediate
48
How to specify a custom Dockerfile name when building an image?
Intermediate

Use the `-f` or `--file` flag during the `docker build` process.

Comprehensive Explanation
Use the `-f` or `--file` flag during the `docker build` process.
Command / Code
docker build -f Dockerfile.prod -t myapp:prod .
Intermediate
49
What is a dangling volume and how to clean it?
Intermediate

A dangling volume is a volume not attached to any container. They can be cleaned up using `docker volume prune`.

Comprehensive Explanation
A dangling volume is a volume not attached to any container. They can be cleaned up using `docker volume prune`.
Intermediate
50
How to inspect detailed configuration of a container?
Intermediate

Use the `docker inspect` command to return low-level information on Docker objects in JSON format.

Comprehensive Explanation
Use the `docker inspect` command to return low-level information on Docker objects in JSON format.
Command / Code
docker inspect <container_id>
Intermediate
51
How does Docker caching work during `docker build`?
Advanced

Docker 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
Docker 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 and exact same instruction. If found, it reuses it. If caching breaks at one layer (e.g. `COPY` a changed file), all subsequent layers are rebuilt.
Advanced
52
Why should you minimize the number of layers in a Docker image?
Advanced

Each `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
Each `RUN`, `COPY`, and `ADD` instruction creates a new layer, which increases the overall image size and build/push/pull time. Combining multiple commands using `&&` in `RUN` reduces empty/intermediate layers resulting in a smaller footprint.
Advanced
53
Explain User Namespace Remapping in Docker.
Advanced

User 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
User 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 where a root process in the container gains root access on the host.
Advanced
54
What is Docker Storage Driver?
Advanced

Storage 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
Storage drivers control how images and containers are stored and managed on your Docker host. They use a union filesystem (like overlay2, btrfs, zfs). `overlay2` is the recommended storage driver for most systems.
Advanced
55
How do you manage secrets in Docker Compose?
Advanced

Docker 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
Docker Compose allows defining secrets using the `secrets` top-level block. These secrets are mounted as files in `/run/secrets/` inside the container, avoiding exposing sensitive data in env variables.
Advanced
56
How do you handle graceful shutdowns of Docker containers?
Advanced

Containers should handle `SIGTERM` signals correctly. By default, `docker stop` sends `SIGTERM`, waits 10s, and then sends `SIGKILL`. Your app must handle `SIGT...

Comprehensive Explanation
Containers should handle `SIGTERM` signals correctly. By default, `docker stop` sends `SIGTERM`, waits 10s, and then sends `SIGKILL`. Your app must handle `SIGTERM` to close DB connections and finish tasks. Note that using `CMD ["node", "app.js"]` rather than `CMD node app.js` ensures signals are passed.
Advanced
57
What is a Node in Docker Swarm?
Advanced

A 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
A 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 (which execute tasks/containers).
Advanced
58
How do you backup, restore, or migrate data volumes?
Advanced

Run 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
Run 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. Reverse the process to restore.
Advanced
59
What are Docker Content Trust (DCT) and Image Signing?
Advanced

DCT 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
DCT 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 client to verify the author and that the image hasn't been tampered with.
Advanced
60
How can you speed up CI/CD pipeline Docker builds?
Advanced

Utilize `--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
Utilize `--cache-from` to use pre-built images as cache sources. Use Docker Buildkit (`DOCKER_BUILDKIT=1`) for parallel execution and better caching. Maximize cache hits by putting infrequent changes (dependencies) at the top of the Dockerfile.
Advanced
61
What is Docker BuildKit?
Advanced

BuildKit is an improved build backend designed to be more efficient, cache-friendly, and secure. Features include concurrent build steps, skipping unused stages...

Comprehensive Explanation
BuildKit is an improved build backend designed to be more efficient, cache-friendly, and secure. Features include concurrent build steps, skipping unused stages, and mounting secrets specifically during build time without leaving traces.
Advanced
62
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
`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 infinite loop and unable to handle new connections, even though the server process is still running.
Advanced
63
How do you limit CPU and Memory for a container?
Advanced

Use flags like `--cpus` and `-m` or `--memory` during `docker run` to restrict resources using namespaces/cgroups.

Comprehensive Explanation
Use flags like `--cpus` and `-m` or `--memory` during `docker run` to restrict resources using namespaces/cgroups.
Command / Code
docker run -it --cpus=".5" --memory="256m" ubuntu /bin/bash
Advanced
64
What is a Zombie Process in a container and how do you prevent it?
Advanced

Zombie 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
Zombie 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` by running `docker run --init` to correctly reap zombie processes.
Advanced
65
How do you configure a container to use a specific DNS server?
Advanced

Pass the `--dns` flag to `docker run` to override the default DNS resolution settings.

Comprehensive Explanation
Pass the `--dns` flag to `docker run` to override the default DNS resolution settings.
Command / Code
docker run -d --dns 8.8.8.8 nginx
Advanced
66
What 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
`scratch` is an explicitly empty image, mainly used as a base for completely self-contained statically linked binaries (like Go applications), producing the smallest possible image.
Advanced
67
Explain what `docker context` is.
Advanced

Docker contexts allow you to easily manage multiple environments (like local Docker, remote servers, Kubernetes) and switch between them seamlessly using `docke...

Comprehensive Explanation
Docker contexts allow you to easily manage multiple environments (like local Docker, remote servers, Kubernetes) and switch between them seamlessly using `docker context use `.
Advanced
68
How do you troubleshoot a container that immediately exits?
Advanced

Check 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
Check 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. `CMD ["echo", "done"]`). You can inspect the container or override the entrypoint with a shell to debug.
Advanced
69
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
`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 service, typically used for administrative tasks or running tests.
Advanced
70
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
`docker wait` blocks until one or more containers stop, then prints their exit codes. Useful for CI/CD scripting.
Advanced
71
What is Macvlan network in Docker?
Advanced

Macvlan 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
Macvlan 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 be directly connected to the physical network.
Advanced
72
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
`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 during both the build process and when the container is running.
Advanced
73
What is Docker's Copy-on-Write (CoW) strategy?
Advanced

Docker 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
Docker 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 writable thin layer where the modification takes place, saving space and time.
Advanced
74
How to log container output to an external system?
Advanced

By using Docker logging drivers. You can configure logging drivers like `json-file` (default), `syslog`, `fluentd`, `awslogs`, or `splunk` either at the daemon ...

Comprehensive Explanation
By using Docker logging drivers. You can configure logging drivers like `json-file` (default), `syslog`, `fluentd`, `awslogs`, or `splunk` either at the daemon level or per container using the `--log-driver` flag.
Advanced
75
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
`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 stacks where you want standard behavior when someone subclasses your framework image.
Advanced
76
You forgot your container's internal IP. How do you find it?
Scenario

Inspect the specific container and filter for the IP address.

Comprehensive Explanation
Inspect the specific container and filter for the IP address.
Command / Code
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_id_or_name>
Scenario
77
Your host is out of space. You want to remove ALL unused Docker data (containers, networks, images, and volumes).
Scenario

Use `docker system prune` with the `-a` and `--volumes` flags.

Comprehensive Explanation
Use `docker system prune` with the `-a` and `--volumes` flags.
Command / Code
docker system prune -a --volumes -f
Scenario
78
How do you enter a bash shell of a running Alpine Linux container to debug?
Scenario

Alpine Linux typically uses `sh` instead of `bash`. Use `docker exec`.

Comprehensive Explanation
Alpine Linux typically uses `sh` instead of `bash`. Use `docker exec`.
Command / Code
docker exec -it <container_name> /bin/sh
Scenario
79
You want to build a Dockerfile named `build.docker` in the `src` directory.
Scenario

Use the `-f` flag to point to the specific file, and set the correct build context.

Comprehensive Explanation
Use the `-f` flag to point to the specific file, and set the correct build context.
Command / Code
docker build -f src/build.docker -t myapp src/
Scenario
80
How do you copy a log file from a container to your host machine?
Scenario

Use the `docker cp` command.

Comprehensive Explanation
Use the `docker cp` command.
Command / Code
docker cp mycontainer:/var/log/app.log ./app.log
Scenario
81
How do you force stop a frozen container without waiting 10 seconds?
Scenario

Use `docker kill`, which immediately sends a `SIGKILL` instead of the graceful `SIGTERM`.

Comprehensive Explanation
Use `docker kill`, which immediately sends a `SIGKILL` instead of the graceful `SIGTERM`.
Command / Code
docker kill <container_name>
Scenario
82
Your database container failed to start. How do you check what happened in the last 20 log lines?
Scenario

Use `docker logs` with the `--tail` flag.

Comprehensive Explanation
Use `docker logs` with the `--tail` flag.
Command / Code
docker logs --tail 20 <container_name>
Scenario
83
How do you start a container, execute an ephemeral command, and ensure it deletion automatically afterwards?
Scenario

Use the `--rm` flag with `docker run`.

Comprehensive Explanation
Use the `--rm` flag with `docker run`.
Command / Code
docker run --rm ubuntu ls -lah
Scenario
84
How do you restart all services defined in a docker-compose file while rebuilding their images?
Scenario

Pass the `--build` flag to `docker-compose up`.

Comprehensive Explanation
Pass the `--build` flag to `docker-compose up`.
Command / Code
docker-compose up -d --build --force-recreate
Scenario
85
You need to export an image to a tarball file to transfer it via USB.
Scenario

Use the `docker save` command.

Comprehensive Explanation
Use the `docker save` command.
Command / Code
docker save -o myimage.tar myimage:latest
Scenario
86
How do you load the Docker image you just transferred via USB?
Scenario

Use the `docker load` command.

Comprehensive Explanation
Use the `docker load` command.
Command / Code
docker load -i myimage.tar
Scenario
87
A container is consuming too much memory and freezing your host. How do you limit it dynamically?
Scenario

Use `docker update` on a running container.

Comprehensive Explanation
Use `docker update` on a running container.
Command / Code
docker update -m 512m <container_name>
Scenario
88
How do you display real-time resource usage statistics for all running containers?
Scenario

Use the `docker stats` command.

Comprehensive Explanation
Use the `docker stats` command.
Command / Code
docker stats
Scenario
89
You want to run a Redis container interactively, testing a few commands, then exit without leaving the container behind.
Scenario

Run it with `--rm` and `-it`.

Comprehensive Explanation
Run it with `--rm` and `-it`.
Command / Code
docker run -it --rm redis redis-cli
Scenario
90
You modified a file locally in your React app. How do you see the changes immediately in the Dockerized app without rebuilding?
Scenario

Use a bind volume mount mapping your local directory to the container directory.

Comprehensive Explanation
Use a bind volume mount mapping your local directory to the container directory.
Command / Code
docker run -v $(pwd)/src:/app/src -p 3000:3000 myreactapp
Scenario
91
How do you see all environment variables available inside a running container?
Scenario

Use `docker exec` to run the `env` command.

Comprehensive Explanation
Use `docker exec` to run the `env` command.
Command / Code
docker exec <container_name> env
Scenario
92
How do you inspect the differences between the container's writable layer and the base image?
Scenario

Use the `docker diff` command. It lists altered, added, and deleted files.

Comprehensive Explanation
Use the `docker diff` command. It lists altered, added, and deleted files.
Command / Code
docker diff <container_name>
Scenario
93
How do you commit a container's file changes into a new image?
Scenario

Use the `docker commit` command.

Comprehensive Explanation
Use the `docker commit` command.
Command / Code
docker commit <container_name> mynewimage:v1
Scenario
94
How do you see the intermediate layers that make up a Docker image?
Scenario

Use the `docker history` command.

Comprehensive Explanation
Use the `docker history` command.
Command / Code
docker history myimage:latest
Scenario
95
How to quickly fetch only the IDs of all running containers?
Scenario

Use `docker ps` with the `-q` (quiet) flag.

Comprehensive Explanation
Use `docker ps` with the `-q` (quiet) flag.
Command / Code
docker ps -q
Scenario
96
How do you stop all running containers using a single command?
Scenario

Pass the output of `docker ps -q` to `docker stop`.

Comprehensive Explanation
Pass the output of `docker ps -q` to `docker stop`.
Command / Code
docker stop $(docker ps -q)
Scenario
97
Your `.env` file requires specific parsing for Docker Compose. How do you verify the compiled compose file before running it?
Scenario

Use the `docker-compose config` command to validate and view the complete configuration.

Comprehensive Explanation
Use the `docker-compose config` command to validate and view the complete configuration.
Command / Code
docker-compose config
Scenario
98
In swarm mode, how do you see all tasks/containers running for a specific service?
Scenario

Use the `docker service ps` command.

Comprehensive Explanation
Use the `docker service ps` command.
Command / Code
docker service ps <service_name>
Scenario
99
How to mount the docker socket into a container so the container can start other containers?
Scenario

Bind mount `/var/run/docker.sock`. (Note: This has massive security implications).

Comprehensive Explanation
Bind mount `/var/run/docker.sock`. (Note: This has massive security implications).
Command / Code
docker run -v /var/run/docker.sock:/var/run/docker.sock myimage
Scenario
100
How do you format output of `docker ps` to only show the container name and its status?
Scenario

Use the `--format` flag with Go templates.

Comprehensive Explanation
Use the `--format` flag with Go templates.
Command / Code
docker ps --format "{{.Names}}: {{.Status}}"
Scenario