{"id":923,"date":"2026-10-11T11:00:00","date_gmt":"2026-10-11T05:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/"},"modified":"2026-10-24T11:08:27","modified_gmt":"2026-10-24T05:38:27","slug":"docker-interview-questions","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/","title":{"rendered":"Docker Interview Questions: 110 Most Asked, with Full Answers"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Docker interview questions come up in almost every backend, DevOps and cloud interview today, because nearly every team ships its apps in containers. This post gives you 110 of the most asked questions, grouped from basic to advanced, and every one of them now has a full answer in simple English, with commands and examples you can try.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you build Go services, first read our <a href=\"https:\/\/smitabharat.com\/blog\/go-docker-deployment\/\">Go Docker deployment guide<\/a>, which builds a tiny image step by step. For Go-specific build and CI questions, see the <a href=\"https:\/\/smitabharat.com\/blog\/go-deployment-interview-questions-part-25\/\">Go deployment interview questions<\/a>. All answers here match current Docker Engine releases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Do Docker Interview Questions Cover?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Docker is a tool that packs your app and everything it needs into one unit called an image. When you run an image, you get a container: a small, isolated process that behaves the same on every machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a shipping container at a port. The crane does not care if it holds rice or laptops, because every container has the same size and hooks. Docker gives software the same idea, so &#8220;it works on my machine&#8221; stops being a problem.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Most Docker interview questions test five areas: images, containers, networking, storage and security. Senior rounds add Docker Compose, production debugging and real scenarios.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Use These Docker Interview Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Do not try to learn 110 answers by heart. Instead, use the list in three passes.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, read each question and try to answer it in two or three sentences before you read the answer.<\/li>\n\n\n<li>Next, practise the marked ones out loud, with a small example from your own work.<\/li>\n\n\n<li>Finally, run the commands from the hands-on section on your laptop, because interviewers love &#8220;have you done this?&#8221; follow-ups.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The table below shows how interview rounds usually use these questions.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Round<\/th><th>Focus<\/th><th>Question range<\/th><\/tr><\/thead><tbody><tr><td>Phone screen<\/td><td>Basics and terms<\/td><td>Q1 to Q25<\/td><\/tr><tr><td>Technical round<\/td><td>Dockerfile, networks, volumes, Compose<\/td><td>Q26 to Q85<\/td><\/tr><tr><td>Senior or DevOps round<\/td><td>Security, production, scenarios<\/td><td>Q86 to Q110<\/td><\/tr><tr><td>Hands-on test<\/td><td>Write a Dockerfile or Compose file<\/td><td>Hands-on section<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How Docker Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every Docker flow follows the same path. You write a Dockerfile, build it into an image, push the image to a registry, and run it as a container anywhere.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-1-1024x640.png\" alt=\"Docker interview questions diagram showing Dockerfile, build, image, registry and running container\" class=\"wp-image-921\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">A Dockerfile builds an image, the registry stores it, and docker run starts it as a container on any host.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Behind the scenes, the Docker CLI sends your commands to the Docker daemon (dockerd). The daemon uses containerd and runc to start the container, and the Linux kernel isolates it with namespaces and cgroups.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Docker Interview Questions with Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Docker interview questions check that you know the core words and ideas. Freshers should be able to answer all of them, so read each answer and try the commands on your laptop.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. What is Docker, and what problem does it solve?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker is a platform to build, ship and run apps inside containers. A container packs your app with its libraries, runtime and settings into one unit. So the app runs the same way on your laptop, a test server and the cloud.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The problem Docker solves is the famous &#8220;it works on my machine&#8221;. Before containers, an app could break on a server because of a different library version, OS package or config. With Docker, you ship the whole environment with the app, so those differences disappear. It also makes setup fast, because a new developer can start the full stack with one command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. What is a container?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A container is a running app that is isolated from other apps on the same machine. It has its own files, network, process list and host name, but it shares the host&#8217;s Linux kernel. Under the hood, a container is just a normal Linux process with extra walls around it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of flats in one building. Each family has its own rooms and front door, but they all share the same foundation, water and electricity lines. Containers share the kernel the same way, which is why they are light and start in seconds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. What is the difference between a container and a virtual machine?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A virtual machine (VM) runs a full guest operating system on top of a hypervisor, with its own kernel. A container shares the host kernel and isolates only the app process. So containers are much smaller and faster to start, while VMs give stronger isolation.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Container<\/th><th>Virtual machine<\/th><\/tr><\/thead><tbody><tr><td>Isolation<\/td><td>Process level, shares host kernel<\/td><td>Full guest OS on a hypervisor<\/td><\/tr><tr><td>Start time<\/td><td>Seconds or less<\/td><td>Usually minutes<\/td><\/tr><tr><td>Size<\/td><td>Megabytes<\/td><td>Gigabytes<\/td><\/tr><tr><td>Density<\/td><td>Many per host<\/td><td>Fewer per host<\/td><\/tr><tr><td>Security boundary<\/td><td>Weaker, kernel is shared<\/td><td>Stronger<\/td><\/tr><tr><td>Best for<\/td><td>Microservices, CI, fast scaling<\/td><td>Mixed OS, strong isolation<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-2-1024x640.png\" alt=\"Docker interview questions comparison of containers and virtual machines\" class=\"wp-image-922\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Containers share the host kernel and start in seconds, while virtual machines each carry a full guest operating system.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So use containers for most modern apps, and use VMs when you need a different kernel or a hard security boundary. Many clouds run containers inside VMs to get both.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4. What is a Docker image?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Docker image is a read-only template that holds everything needed to run an app: a base file system, your code or binary, libraries, environment variables and the start command. You build an image from a Dockerfile, and you can store it in a registry and share it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An image is made of layers stacked on top of each other. Each layer stores only the changes from the one below, so images that share a base layer save disk space and download time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5. What is the difference between an image and a container?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An image is the template, and a container is a running copy of it. A simple way to remember it: an image is a recipe, and a container is the dish you cook from it. You can cook many dishes from one recipe, and you can start many containers from one image.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Technically, a container adds a thin writable layer on top of the image&#8217;s read-only layers. Anything the container writes goes into that writable layer, so the image itself never changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6. What is a Dockerfile?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Dockerfile is a plain text file with step-by-step instructions to build an image. Each line starts with an instruction, such as <code>FROM<\/code>, <code>COPY<\/code>, <code>RUN<\/code> or <code>CMD<\/code>. Then <code>docker build<\/code> reads the file and creates the image.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM golang:1.27 AS build\nWORKDIR \/src\nCOPY . .\nRUN go build -o \/app .\n\nFROM debian:bookworm-slim\nCOPY --from=build \/app \/app\nCMD [\"\/app\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Because the Dockerfile is code, you keep it in Git next to your app. So every build is repeatable, and anyone can see exactly how the image was made.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7. What is Docker Hub, and what is a registry?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A registry is a server that stores and shares Docker images, like GitHub but for images. You <code>docker push<\/code> an image to it and <code>docker pull<\/code> it on another machine. Docker Hub is Docker&#8217;s public registry and the default one, so <code>docker pull nginx<\/code> downloads from Docker Hub.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Companies also use private registries, such as Amazon ECR, Google Artifact Registry, Azure Container Registry, GitHub Container Registry or a self-hosted Harbor. Docker Hub has pull rate limits for anonymous and free users, so teams usually log in or use a mirror in CI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8. What is the Docker daemon, and what does the Docker CLI do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Docker daemon, <code>dockerd<\/code>, is a background service that does the real work. It builds images, starts and stops containers, and manages networks and volumes. The Docker CLI, the <code>docker<\/code> command you type, is only a client.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you run <code>docker ps<\/code>, the CLI sends a request to the daemon through a REST API, usually over the Unix socket <code>\/var\/run\/docker.sock<\/code>. The daemon answers, and the CLI prints the result. So the CLI can also talk to a daemon on another machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9. What are containerd and runc, and how do they relate to Docker?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker is built from several layers of tools. <code>containerd<\/code> is a container runtime that manages the full life of containers: pulling images, storing them, and starting and stopping containers. <code>runc<\/code> is a small low-level tool that actually creates the container using Linux namespaces and cgroups.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So the chain looks like this: <code>docker<\/code> CLI talks to <code>dockerd<\/code>, <code>dockerd<\/code> talks to <code>containerd<\/code>, and <code>containerd<\/code> uses <code>runc<\/code> to start each container. Kubernetes can use <code>containerd<\/code> directly, without Docker, which is why Docker images still run on Kubernetes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10. What is the OCI (Open Container Initiative), and why does it matter?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The OCI is an open group, under the Linux Foundation, that sets standards for containers. It has three main specs: the image format, the runtime (how to run a container) and the distribution (how registries share images).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It matters because it stops lock-in. An image built with Docker follows the OCI image format, so it runs on containerd, CRI-O, Podman or any other OCI tool. So you can build with one tool and run with another.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11. What happens step by step when you run docker run nginx?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is a classic question, so learn the steps in order.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, the CLI sends the request to the Docker daemon.<\/li>\n\n\n<li>Next, the daemon checks if the <code>nginx:latest<\/code> image is on the machine. If not, it pulls it from Docker Hub.<\/li>\n\n\n<li>Then it creates a new container from the image and adds a writable layer on top.<\/li>\n\n\n<li>It connects the container to the default bridge network and gives it an IP address.<\/li>\n\n\n<li>After that, containerd and runc start the process with its own namespaces and cgroups.<\/li>\n\n\n<li>Finally, nginx starts as the main process (PID 1) inside the container, and its output goes to the container logs.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Since no <code>-d<\/code> flag was given, the terminal stays attached to the container&#8217;s output until you stop it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12. What is an image tag, and why is latest a risky tag?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A tag is a readable label for an image version, written after a colon, such as <code>nginx:1.27<\/code> or <code>shop-api:2.3.1<\/code>. If you do not give a tag, Docker uses <code>latest<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>latest<\/code> is risky because it is just a name, not &#8220;the newest version&#8221;. It can point to a different image tomorrow. So two servers pulling <code>latest<\/code> on different days can run different code, and rollbacks become hard. In production, always use a fixed version tag, or better, a digest.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13. What is an image digest, and when would you pin one?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A digest is a unique fingerprint of an image&#8217;s content, a SHA-256 hash such as <code>nginx@sha256:4c0f...<\/code>. Unlike a tag, a digest can never point to different content. If one byte changes, the digest changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You pin a digest when you need exact, repeatable builds and deploys, for example for base images in production Dockerfiles or for security-approved images. Tools like Renovate or Dependabot can update pinned digests for you when new versions come out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14. How do you list running containers and all containers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>docker ps<\/code> lists only running containers. <code>docker ps -a<\/code> lists all containers, including stopped ones. You can also filter and format the output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker ps                                  # running containers\ndocker ps -a                               # all containers, running and stopped\ndocker ps -q                               # only the container IDs\ndocker ps --filter \"status=exited\"         # only stopped containers\ndocker ps --format \"{{.Names}}\\t{{.Status}}\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15. How do you stop, start, restart and remove a container?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each action has a simple command. You can use the container name or ID.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker stop api        # stop gracefully (SIGTERM, then SIGKILL)\ndocker start api       # start a stopped container again\ndocker restart api     # stop, then start\ndocker rm api          # remove a stopped container\ndocker rm -f api       # stop and remove in one step\ndocker container prune # remove all stopped containers<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Removing a container deletes its writable layer, so any data not in a volume is lost.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16. What is the difference between docker stop and docker kill?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>docker stop<\/code> sends SIGTERM to the main process, which asks it to shut down cleanly. If the process is still running after a grace period, 10 seconds by default, Docker sends SIGKILL. <code>docker kill<\/code> sends SIGKILL straight away, so the process has no chance to clean up.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So use <code>docker stop<\/code> normally, because it lets your app finish requests, close database connections and save state. Use <code>docker kill<\/code> only when a container is stuck. You can change the grace time with <code>docker stop -t 30 api<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17. How do you see the logs of a container?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>docker logs<\/code>. It shows everything the main process wrote to standard output and standard error. That is why containerised apps should log to stdout and stderr, not to files.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker logs api                 # all logs so far\ndocker logs -f api              # follow new lines live\ndocker logs --tail 100 api      # only the last 100 lines\ndocker logs --since 10m api     # logs from the last 10 minutes\ndocker logs -t api              # add timestamps<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18. How do you open a shell inside a running container?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>docker exec -it<\/code> with a shell program. The <code>-i<\/code> keeps input open, and <code>-t<\/code> gives you a terminal.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker exec -it api sh          # most small images have sh\ndocker exec -it api bash        # if bash is installed\ndocker exec api ls \/app         # run one command without a shell<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the image has no shell, such as distroless or scratch, <code>exec<\/code> fails. Then you use a debug container instead, which is covered in the scenario questions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19. What is Docker Desktop, and how is it different from Docker Engine?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker Engine is the core open-source part: the daemon, the CLI and the runtime. It runs natively on Linux. Docker Desktop is an app for macOS, Windows and Linux that bundles Docker Engine inside a small Linux VM, plus a GUI, Docker Compose, Kubernetes, BuildKit and extra tools.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On Mac and Windows you need Desktop (or another tool like Rancher Desktop, Colima or Podman), because containers need a Linux kernel. Also, Docker Desktop is free for personal use, education and small businesses, but larger companies need a paid subscription. Docker Engine on Linux servers is free.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20. Which Linux kernel features make containers possible?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Containers are built on three main Linux features.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Namespaces:<\/strong> give each container its own view of processes, network, mounts, host name and users.<\/li>\n\n\n<li><strong>Cgroups (control groups):<\/strong> limit and measure how much CPU, memory and I\/O a container can use.<\/li>\n\n\n<li><strong>Union file systems, such as OverlayFS:<\/strong> stack image layers and add a writable layer on top, without copying everything.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Security features add more walls, such as capabilities, seccomp and AppArmor or SELinux. Together, they make a normal process look like its own small machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21. What are namespaces, and which ones does Docker use?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A namespace limits what a process can see. Inside a namespace, the process sees only its own resources, as if it were alone on the machine. Docker creates a set of namespaces for every container.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Namespace<\/th><th>What it isolates<\/th><\/tr><\/thead><tbody><tr><td>PID<\/td><td>Process IDs, so the app sees itself as PID 1<\/td><\/tr><tr><td>NET<\/td><td>Network interfaces, IP addresses and ports<\/td><\/tr><tr><td>MNT<\/td><td>Mount points and the file system view<\/td><\/tr><tr><td>UTS<\/td><td>Host name and domain name<\/td><\/tr><tr><td>IPC<\/td><td>Shared memory and message queues<\/td><\/tr><tr><td>USER<\/td><td>User and group IDs (used in rootless and userns modes)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So two containers can both listen on port 80 and both have a process with PID 1, because each has its own namespaces.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22. What are cgroups, and what do they limit?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cgroups (control groups) are a Linux feature that limits and tracks how much of the machine a group of processes can use. Docker puts each container in its own cgroup. So one busy container cannot use all the CPU or memory and starve the others.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cgroups can limit memory, CPU time, the number of processes (PIDs) and disk I\/O. If a container goes over its memory limit, the kernel&#8217;s OOM killer stops it. Most current Linux systems use cgroups v2, which Docker supports fully.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q23. Can you run Windows containers on Linux, or Linux containers on Windows?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A container uses the host&#8217;s kernel, so a Windows container needs a Windows kernel and a Linux container needs a Linux kernel. So you cannot run Windows containers on a Linux host.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On Windows, Docker Desktop runs Linux containers inside a lightweight Linux VM (using WSL 2), so Linux containers do work there. It can also switch to Windows container mode to run native Windows containers. On macOS, Docker Desktop also uses a Linux VM.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q24. What is the difference between docker run and docker start?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>docker run<\/code> creates a new container from an image and starts it, all in one step. <code>docker start<\/code> starts an existing container that was stopped. So <code>run<\/code> is like buying a new phone and turning it on, and <code>start<\/code> is like turning your old phone back on.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each <code>docker run<\/code> gives you a fresh container with a clean writable layer. A restarted container keeps the files it wrote before it stopped, as long as you did not remove it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q25. What do the -d, -it and &#8211;rm flags do in docker run?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These are the most used <code>docker run<\/code> flags.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Flag<\/th><th>Meaning<\/th><th>Example use<\/th><\/tr><\/thead><tbody><tr><td><code>-d<\/code><\/td><td>Detached: run in the background and print the container ID<\/td><td>Servers and databases<\/td><\/tr><tr><td><code>-i<\/code><\/td><td>Keep standard input open<\/td><td>Interactive tools<\/td><\/tr><tr><td><code>-t<\/code><\/td><td>Give the container a terminal<\/td><td>Shells, with <code>-i<\/code> as <code>-it<\/code><\/td><\/tr><tr><td><code>--rm<\/code><\/td><td>Remove the container when it stops<\/td><td>One-off tasks and tests<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --name web -p 8080:80 nginx:1.27   # background server\ndocker run -it --rm alpine:3.22 sh               # throwaway shell, removed on exit<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Dockerfile and Image Docker Interview Questions with Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most technical rounds spend the longest time on images. So these Docker interview questions focus on the Dockerfile, the build cache and image size.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q26. What are image layers, and how does the build cache use them?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each instruction in a Dockerfile that changes files, such as <code>RUN<\/code>, <code>COPY<\/code> or <code>ADD<\/code>, creates a new layer. A layer stores only the changes from the layer below. The final image is all the layers stacked together, like transparent sheets placed one on top of another.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you build again, Docker checks each instruction from the top. If the instruction and its inputs are the same as last time, it reuses the cached layer instead of running it again. However, once one layer changes, every layer after it must be rebuilt. So the order of your instructions decides how fast your builds are.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q27. Why should you copy dependency files before the rest of your code?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Dependencies change rarely, but your code changes all the time. If you copy all the code first and then download dependencies, every small code change breaks the cache, and the slow download runs again.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So copy only the dependency files first, download dependencies, and copy the rest of the code after that. Then a code change only rebuilds the last few layers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM golang:1.27\nWORKDIR \/src\n\nCOPY go.mod go.sum .\/     # changes rarely\nRUN go mod download       # cached until go.mod or go.sum changes\n\nCOPY . .                  # changes often\nRUN go build -o \/app .\/cmd\/api<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The same idea works for other languages, such as <code>package.json<\/code> for Node.js or <code>requirements.txt<\/code> for Python.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q28. What is the difference between RUN, CMD and ENTRYPOINT?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These three look similar, but they run at different times.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Instruction<\/th><th>When it runs<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td><code>RUN<\/code><\/td><td>At build time<\/td><td>Install packages, compile code, creates a layer<\/td><\/tr><tr><td><code>CMD<\/code><\/td><td>When the container starts<\/td><td>Default command or default arguments, easy to override<\/td><\/tr><tr><td><code>ENTRYPOINT<\/code><\/td><td>When the container starts<\/td><td>The main program that always runs<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So <code>RUN apt-get install curl<\/code> happens once while building the image. <code>CMD<\/code> and <code>ENTRYPOINT<\/code> describe what happens each time a container starts. If a Dockerfile has several <code>CMD<\/code> lines, only the last one counts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q29. What is the difference between shell form and exec form in CMD?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Exec form is written as a JSON list, such as <code>CMD [\"\/app\", \"--port\", \"8080\"]<\/code>. Docker runs the program directly, so it becomes PID 1 and receives signals like SIGTERM. Shell form is written as plain text, such as <code>CMD \/app --port 8080<\/code>. Docker wraps it in <code>\/bin\/sh -c<\/code>, so the shell becomes PID 1.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The shell form causes a common problem. The shell may not pass SIGTERM to your app, so <code>docker stop<\/code> waits the full timeout and then kills it. So always prefer exec form for <code>CMD<\/code> and <code>ENTRYPOINT<\/code>, and use shell form only when you need shell features like variable expansion.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q30. How do CMD and ENTRYPOINT work together?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When both are set, <code>CMD<\/code> becomes the default arguments to <code>ENTRYPOINT<\/code>. Anything you type after the image name in <code>docker run<\/code> replaces <code>CMD<\/code>, but <code>ENTRYPOINT<\/code> stays.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ENTRYPOINT [\"\/app\"]\nCMD [\"--port\", \"8080\"]<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run shop-api                 # runs: \/app --port 8080\ndocker run shop-api --port 9090     # runs: \/app --port 9090\ndocker run --entrypoint sh -it shop-api   # replace the entrypoint for debugging<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So use <code>ENTRYPOINT<\/code> for the program and <code>CMD<\/code> for its default flags. This makes the image act like a command-line tool.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q31. What is the difference between COPY and ADD?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>COPY<\/code> copies files and folders from the build context into the image, and nothing more. <code>ADD<\/code> does the same, but it can also download a file from a URL and unpack a local tar archive automatically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Those extra features can surprise you, for example an archive being unpacked when you just wanted to copy it. So the Docker docs recommend <code>COPY<\/code> for normal use. Use <code>ADD<\/code> only when you really want the auto-unpack, or to add a remote file with a checksum check.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q32. What does WORKDIR do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>WORKDIR<\/code> sets the working folder for the instructions that follow, such as <code>RUN<\/code>, <code>COPY<\/code>, <code>CMD<\/code> and <code>ENTRYPOINT<\/code>. It also creates the folder if it does not exist.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>WORKDIR \/app\nCOPY . .          # copies into \/app\nRUN go build .    # runs inside \/app<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>WORKDIR<\/code> instead of <code>RUN cd \/app &amp;&amp; ...<\/code>, because a <code>cd<\/code> inside <code>RUN<\/code> only lasts for that one line.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q33. What is the difference between ARG and ENV?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ARG<\/code> defines a variable that exists only during the build. You set it with <code>docker build --build-arg VERSION=1.2<\/code>. <code>ENV<\/code> sets an environment variable that is saved in the image, so it exists during the build and also inside every running container.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>ARG<\/th><th>ENV<\/th><\/tr><\/thead><tbody><tr><td>Available at build time<\/td><td>Yes<\/td><td>Yes<\/td><\/tr><tr><td>Available in running containers<\/td><td>No<\/td><td>Yes<\/td><\/tr><tr><td>Set from outside<\/td><td><code>--build-arg<\/code><\/td><td><code>-e<\/code> on <code>docker run<\/code><\/td><\/tr><tr><td>Typical use<\/td><td>Versions, build options<\/td><td>App settings, <code>PATH<\/code>, <code>TZ<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Neither one is safe for secrets, because both can show up in the image history. Use build secrets instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q34. What does EXPOSE do, and does it publish a port?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>EXPOSE 8080<\/code> only documents which port the app inside the container listens on. It does not open or publish the port to the host. It is a note for people and tools reading the image.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To actually reach the port from outside, you publish it with <code>-p 8080:8080<\/code> on <code>docker run<\/code>, or a <code>ports<\/code> entry in Compose. The <code>-P<\/code> flag publishes all exposed ports to random host ports.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q35. What is a multi-stage build, and why does it shrink images?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A multi-stage build uses more than one <code>FROM<\/code> line in one Dockerfile. The first stage has all the build tools, such as a compiler, and builds your app. After that, the final stage starts from a small base image and copies only the finished files from the first stage with <code>COPY --from<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Stage 1: build\nFROM golang:1.27 AS build\nWORKDIR \/src\nCOPY go.mod go.sum .\/\nRUN go mod download\nCOPY . .\nRUN CGO_ENABLED=0 go build -o \/app .\/cmd\/api\n\n# Stage 2: run\nFROM gcr.io\/distroless\/static-debian12:nonroot\nCOPY --from=build \/app \/app\nENTRYPOINT [\"\/app\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The compiler, source code and caches never reach the final image. So a Go image can drop from over 800 MB to around 10 to 20 MB. A smaller image downloads faster and has fewer packages for attackers to use.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q36. How do you choose a base image: full, slim, Alpine, distroless or scratch?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The base image is the starting point of your image, and it decides the size and what tools are inside. The table below compares the common choices.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Base image<\/th><th>Rough size<\/th><th>Has a shell and package manager<\/th><th>Good for<\/th><\/tr><\/thead><tbody><tr><td>Full (<code>debian<\/code>, <code>ubuntu<\/code>)<\/td><td>75 to 120 MB+<\/td><td>Yes<\/td><td>Builds, apps needing many tools<\/td><\/tr><tr><td>Slim (<code>debian:bookworm-slim<\/code>)<\/td><td>About 30 MB<\/td><td>Yes<\/td><td>Most apps that need glibc<\/td><\/tr><tr><td>Alpine<\/td><td>About 5 to 8 MB<\/td><td>Yes, uses musl and <code>apk<\/code><\/td><td>Small images, if musl is fine<\/td><\/tr><tr><td>Distroless<\/td><td>About 2 to 20 MB<\/td><td>No shell<\/td><td>Production apps, smaller attack surface<\/td><\/tr><tr><td>scratch<\/td><td>0 MB<\/td><td>Nothing at all<\/td><td>Static binaries such as Go<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So for a Go service built with <code>CGO_ENABLED=0<\/code>, distroless static or scratch is a great choice. For apps with native libraries, start with slim.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q37. What problems can Alpine cause because it uses musl instead of glibc?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alpine uses the musl C library instead of glibc, which most Linux distributions use. Most of the time this is fine, but it can cause a few surprises.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Programs built for glibc may not run, or need extra packages, so prebuilt binaries can fail.<\/li>\n\n\n<li>Python and Node.js packages with native code often need to be compiled from source, which makes builds slower and images bigger.<\/li>\n\n\n<li>DNS and memory allocation behave a little differently, which has caused performance and lookup issues in some apps.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For Go, a static binary built with <code>CGO_ENABLED=0<\/code> does not use any C library, so Alpine, distroless and scratch all work well.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q38. What is a .dockerignore file, and why is it important?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A <code>.dockerignore<\/code> file lists files and folders that should not be sent to the Docker builder. It works like <code>.gitignore<\/code>. Without it, Docker sends your whole project folder as the build context, including <code>.git<\/code>, <code>node_modules<\/code>, logs and secret files.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.git\nnode_modules\n*.log\n.env\nbin\/\ntmp\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It makes builds faster, because less data is sent. It also stops secrets like <code>.env<\/code> from ending up in the image by accident with <code>COPY . .<\/code>, and avoids breaking the cache when unrelated files change.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q39. How do you reduce the size of a Docker image?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use several techniques together.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, use a multi-stage build, so build tools stay out of the final image.<\/li>\n\n\n<li>Next, pick a small base image, such as slim, Alpine, distroless or scratch.<\/li>\n\n\n<li>Then add a <code>.dockerignore<\/code> file, so only needed files are copied.<\/li>\n\n\n<li>Also, install only runtime packages, with options like <code>apt-get install --no-install-recommends<\/code>.<\/li>\n\n\n<li>Clean package caches in the same <code>RUN<\/code> line that installs them.<\/li>\n\n\n<li>Finally, check the result with <code>docker images<\/code> and see which layers are big with <code>docker history<\/code>.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q40. Why should you join related RUN commands in one layer?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each <code>RUN<\/code> creates a layer, and a later layer cannot shrink an earlier one. If you install packages in one <code>RUN<\/code> and delete the cache in the next <code>RUN<\/code>, the cache files still live in the first layer, so the image does not get smaller.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Good: install and clean up in the same layer\nRUN apt-get update \\\n    &amp;&amp; apt-get install -y --no-install-recommends ca-certificates curl \\\n    &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Joining <code>apt-get update<\/code> and <code>install<\/code> also avoids a stale cache. If they were separate, Docker could reuse an old <code>update<\/code> layer and install outdated packages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q41. What is BuildKit, and what does it improve?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">BuildKit is Docker&#8217;s modern build engine, and it has been the default builder since Docker Engine 23.0. It replaced the older builder and brought many improvements.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Parallel stages:<\/strong> independent build stages run at the same time.<\/li>\n\n\n<li><strong>Smarter caching:<\/strong> it skips stages that the final image does not need, and supports cache import and export for CI.<\/li>\n\n\n<li><strong>Build secrets and SSH:<\/strong> you can use secrets during a build without saving them in a layer.<\/li>\n\n\n<li><strong>Cache mounts:<\/strong> keep package download caches between builds.<\/li>\n\n\n<li><strong>Multi-platform builds:<\/strong> build for amd64 and arm64 with <code>docker buildx<\/code>.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q42. How do you pass secrets to a build without saving them in a layer?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a BuildKit secret mount. The secret is mounted as a file only while that one <code>RUN<\/code> step runs, and it is never written into any layer or the image history.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Dockerfile\nRUN --mount=type=secret,id=npm_token \\\n    NPM_TOKEN=$(cat \/run\/secrets\/npm_token) npm ci<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>docker build --secret id=npm_token,src=$HOME\/.npm_token -t web:1.0 .<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For private Git repositories, you can use <code>--mount=type=ssh<\/code> with <code>docker build --ssh default<\/code>, so your SSH key is never copied. Never use <code>ARG<\/code> or <code>ENV<\/code> for secrets, because they can be seen with <code>docker history<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q43. What is a cache mount in BuildKit?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A cache mount keeps a folder between builds, outside the image layers. It is great for package caches, such as the Go module and build cache, npm or pip. So even when a layer must rebuild, the downloads are already there, and the build is much faster.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RUN --mount=type=cache,target=\/go\/pkg\/mod \\\n    --mount=type=cache,target=\/root\/.cache\/go-build \\\n    go build -o \/app .\/cmd\/api<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The cached files are not part of the final image, so the image stays small.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q44. How do you build images for more than one CPU type, such as amd64 and arm64?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>docker buildx build<\/code> with the <code>--platform<\/code> flag. It builds one image for each platform and pushes them together under one tag, as a multi-platform image (an image index). When someone pulls the tag, Docker picks the right version for their CPU automatically.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker buildx build \\\n  --platform linux\/amd64,linux\/arm64 \\\n  -t registry.example.com\/shop-api:1.4.0 \\\n  --push .<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This matters because many developers use Apple Silicon (arm64) laptops, and many clouds offer cheaper arm64 servers. For Go, cross-compiling is very fast, because you can set <code>GOOS<\/code> and <code>GOARCH<\/code> in the build stage instead of emulating the other CPU.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q45. What does docker buildx do?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>docker buildx<\/code> is the CLI plugin for BuildKit, and it gives you advanced build features. In current Docker versions, <code>docker build<\/code> itself uses buildx and BuildKit behind the scenes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With buildx you can build for many platforms, create separate builder instances (including remote ones or ones running in Kubernetes), export and import build cache to a registry for fast CI builds, and use <code>docker buildx bake<\/code> to build many images from one config file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q46. What is the HEALTHCHECK instruction?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>HEALTHCHECK<\/code> tells Docker how to check that the app inside a container is working, not just that the process is running. Docker runs the check command on a schedule and marks the container as <code>starting<\/code>, <code>healthy<\/code> or <code>unhealthy<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \\\n  CMD [\"\/app\", \"healthcheck\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Docker Compose can wait for a healthy status before starting other services. However, Kubernetes ignores the Dockerfile <code>HEALTHCHECK<\/code> and uses its own liveness and readiness probes. Also, distroless images have no <code>curl<\/code>, so a small health command built into your own binary works well.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q47. What does the USER instruction do, and why use it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>USER<\/code> sets which user runs the following <code>RUN<\/code> steps and the main process of the container. By default, containers run as root, which is risky. If an attacker breaks into your app, root inside the container makes it easier to damage the container or escape to the host.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM debian:bookworm-slim\nRUN useradd --system --uid 10001 appuser\nCOPY --chown=appuser:appuser app \/app\nUSER 10001\nENTRYPOINT [\"\/app\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using a numeric user ID is a good habit, because tools like Kubernetes can then check that the container does not run as root. Distroless images offer a <code>nonroot<\/code> variant with a ready-made user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q48. How do you tag and push an image to a private registry?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The image name must include the registry address. So you tag the image with that full name, log in, then push.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker build -t shop-api:1.4.0 .\ndocker tag shop-api:1.4.0 123456789012.dkr.ecr.ap-south-1.amazonaws.com\/shop-api:1.4.0\naws ecr get-login-password --region ap-south-1 | \\\n  docker login --username AWS --password-stdin 123456789012.dkr.ecr.ap-south-1.amazonaws.com\ndocker push 123456789012.dkr.ecr.ap-south-1.amazonaws.com\/shop-api:1.4.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For other registries, the steps are the same: <code>docker login registry.example.com<\/code>, then tag and push. In CI, use short-lived tokens instead of saved passwords.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q49. How do you inspect the layers and history of an image?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker gives you a few commands to look inside an image.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker history shop-api:1.4.0          # each layer, its size and the instruction\ndocker image inspect shop-api:1.4.0    # full JSON: env, entrypoint, layers, labels\ndocker image ls                        # sizes of local images<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>docker history<\/code> is the quickest way to find which instruction made the image big. Free tools like <code>dive<\/code> go further and show which files each layer added, so you can spot leftovers like caches.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q50. What is a dangling image, and how do you clean up unused images?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A dangling image is an image layer with no tag, shown as <code>&lt;none&gt;:&lt;none&gt;<\/code>. It usually appears when you rebuild an image with the same tag, so the old image loses its name. Dangling images just waste disk space.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker image prune          # remove dangling images\ndocker image prune -a       # remove all images not used by any container\ndocker system df            # see how much space images, containers and volumes use\ndocker system prune         # remove stopped containers, unused networks, dangling images, build cache<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Be careful with <code>-a<\/code> and <code>--volumes<\/code>, because they remove more than you might expect. On CI machines, run a prune step regularly so the disk does not fill up.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Container Lifecycle and Networking Docker Interview Questions with Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once a container runs, you must stop it cleanly and connect it to other services. These Docker interview questions cover both, and they are where many candidates get stuck.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q51. What are the states a container can be in?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A container moves through a few simple states during its life. You can see the state with <code>docker ps -a<\/code> or <code>docker inspect<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>State<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td>created<\/td><td>Made with <code>docker create<\/code>, but not started yet<\/td><\/tr><tr><td>running<\/td><td>The main process is running<\/td><\/tr><tr><td>paused<\/td><td>Processes are frozen with <code>docker pause<\/code><\/td><\/tr><tr><td>restarting<\/td><td>Docker is restarting it because of a restart policy<\/td><\/tr><tr><td>exited<\/td><td>The main process stopped, with an exit code<\/td><\/tr><tr><td>removing<\/td><td>Docker is deleting it<\/td><\/tr><tr><td>dead<\/td><td>Removal failed part way, which is rare<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A container lives exactly as long as its main process. When that process ends, the container moves to <code>exited<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q52. What do restart policies do: no, on-failure, always and unless-stopped?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A restart policy tells Docker what to do when a container stops. You set it with <code>--restart<\/code> on <code>docker run<\/code>, or <code>restart:<\/code> in Compose.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Policy<\/th><th>What it does<\/th><\/tr><\/thead><tbody><tr><td><code>no<\/code><\/td><td>Never restart. This is the default<\/td><\/tr><tr><td><code>on-failure[:max]<\/code><\/td><td>Restart only if the exit code is not 0, optionally up to a maximum number of tries<\/td><\/tr><tr><td><code>always<\/code><\/td><td>Always restart, and also start it again when the Docker daemon starts<\/td><\/tr><tr><td><code>unless-stopped<\/code><\/td><td>Like <code>always<\/code>, but not if you stopped it by hand before the daemon restarted<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So <code>unless-stopped<\/code> is a good default for long-running services on a single server. In Kubernetes, the platform handles restarts instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q53. Why should a container run only one main process?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker watches only the main process (PID 1). If you run several apps in one container, such as a web server and a database, Docker cannot tell if one of them crashed, logs get mixed up, and you cannot scale or update them separately.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So the usual rule is one concern per container. Run the API and the database as two containers and connect them with a network. A container can still have helper child processes, such as worker processes started by nginx, as long as there is one clear main job.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q54. What is PID 1 inside a container, and why does signal handling matter?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The main process in a container gets process ID 1. In Linux, PID 1 is special. It does not get the default signal behaviour, so if it does not set up its own handler for SIGTERM, the signal is ignored. PID 1 is also expected to clean up finished child processes (zombie processes).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So when <code>docker stop<\/code> sends SIGTERM, an app that does not handle it just keeps running, and Docker kills it after the timeout. Your app should catch SIGTERM and shut down cleanly. In Go, <code>signal.NotifyContext<\/code> makes this easy.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)\ndefer stop()\n\n&lt;-ctx.Done() \/\/ wait for docker stop\nlog.Println(\"shutting down\")\nsrv.Shutdown(context.Background()) \/\/ finish in-flight requests<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q55. How does docker stop send signals, and what is the default timeout?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>docker stop<\/code> sends the stop signal, which is SIGTERM by default, to PID 1. Then it waits for the grace period, 10 seconds by default. If the container has not exited by then, Docker sends SIGKILL, which cannot be ignored.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can change the timeout with <code>docker stop -t 30<\/code>, or <code>stop_grace_period<\/code> in Compose. You can change the signal with the <code>STOPSIGNAL<\/code> instruction in the Dockerfile, for example <code>STOPSIGNAL SIGQUIT<\/code> for nginx graceful shutdown.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q56. What is the &#8211;init flag used for?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>docker run --init<\/code> adds a tiny init program (tini) as PID 1. It starts your app as its child, passes signals like SIGTERM to it, and cleans up zombie processes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is useful when your app was not written to be PID 1, for example a shell script or a program that starts child processes. You can also add tini inside the image with <code>ENTRYPOINT [\"tini\", \"--\", \"\/app\"]<\/code>. A Go app that handles SIGTERM and starts no child processes does not need it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q57. What network drivers does Docker have: bridge, host, none, overlay and macvlan?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker networking uses drivers, and each one connects containers in a different way.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Driver<\/th><th>What it does<\/th><th>Typical use<\/th><\/tr><\/thead><tbody><tr><td>bridge<\/td><td>Private network on one host, with NAT to the outside<\/td><td>Default for single-host containers<\/td><\/tr><tr><td>host<\/td><td>Container uses the host&#8217;s network directly, no isolation<\/td><td>Very high network performance<\/td><\/tr><tr><td>none<\/td><td>No network at all<\/td><td>Batch jobs that need no network<\/td><\/tr><tr><td>overlay<\/td><td>Network that spans many Docker hosts<\/td><td>Docker Swarm services<\/td><\/tr><tr><td>macvlan<\/td><td>Container gets its own MAC address on the physical network<\/td><td>Apps that must look like real devices<\/td><\/tr><tr><td>ipvlan<\/td><td>Like macvlan, but shares the host MAC address<\/td><td>Networks that limit MAC addresses<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Most of the time you use user-defined bridge networks on one host, and Kubernetes networking in clusters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q58. What is the default bridge network, and how is a user-defined bridge better?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you start a container with no network option, Docker attaches it to the default network called <code>bridge<\/code> (the <code>docker0<\/code> interface). A user-defined bridge is one you create with <code>docker network create<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Default bridge<\/th><th>User-defined bridge<\/th><\/tr><\/thead><tbody><tr><td>Find containers by name (DNS)<\/td><td>No, only by IP<\/td><td>Yes<\/td><\/tr><tr><td>Isolation<\/td><td>All default containers share it<\/td><td>Only containers you attach<\/td><\/tr><tr><td>Connect or disconnect a running container<\/td><td>Must recreate<\/td><td>Yes, at any time<\/td><\/tr><tr><td>Recommended<\/td><td>For quick tests only<\/td><td>For real apps<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So always create your own network for apps that talk to each other. Docker Compose does this for you automatically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q59. How do containers on the same network find each other by name?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On a user-defined network, Docker runs an embedded DNS server. Each container is registered under its name and any network aliases. So a container can call another one by name, and Docker turns the name into the right IP address.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker network create shop-net\ndocker run -d --name db --network shop-net postgres:17\ndocker run -d --name api --network shop-net -e DB_HOST=db shop-api:1.4.0\n# inside api, the host name \"db\" resolves to the database container<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is much better than using IP addresses, because container IPs change every time a container is recreated.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q60. What is the difference between EXPOSE and publishing a port with -p?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>EXPOSE<\/code> in a Dockerfile only documents the port the app uses. Nothing outside the container can reach it because of <code>EXPOSE<\/code> alone. Publishing with <code>-p<\/code> actually opens a port on the host and forwards traffic to the container.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Containers on the same Docker network can always reach each other on any port the app listens on, with no <code>EXPOSE<\/code> or <code>-p<\/code> needed. So you only publish ports that people or programs outside Docker must use, such as the API port, and keep the database unpublished.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q61. What does -p 8080:80 mean?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It means &#8220;forward port 8080 on the host to port 80 inside the container&#8221;. The format is <code>host:container<\/code>. So if nginx listens on port 80 inside the container, you open <code>http:\/\/localhost:8080<\/code> in your browser.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d -p 8080:80 nginx:1.27           # all host IPs, port 8080\ndocker run -d -p 127.0.0.1:8080:80 nginx:1.27 # only reachable from this machine\ndocker run -d -p 80 nginx:1.27                # random host port<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By default, a published port listens on all host interfaces, so it can be reachable from the outside network. Bind to <code>127.0.0.1<\/code> for services that should stay local, such as a database on your laptop.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q62. When would you use host networking?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With <code>--network host<\/code>, the container shares the host&#8217;s network stack. There is no separate IP and no port mapping, so the app listens directly on the host&#8217;s ports.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use it when you need the best network performance, when an app must see the host&#8217;s real network interfaces (such as some monitoring agents), or when it uses many dynamic ports. The downsides are no network isolation and possible port conflicts. Also, host networking works fully only on Linux. On Docker Desktop it has limits, because containers run inside a VM.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q63. How do you connect a container to two networks?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Start it on one network, then attach the second with <code>docker network connect<\/code>. The container then gets one network interface and IP address for each network.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker network create frontend\ndocker network create backend\ndocker run -d --name api --network frontend shop-api:1.4.0\ndocker network connect backend api<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is a common way to split traffic. For example, the proxy and API share <code>frontend<\/code>, while only the API and database share <code>backend<\/code>. So the proxy can never talk to the database directly. In Compose, you list several networks under the service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q64. How does DNS work inside a Docker network?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On a user-defined network, each container&#8217;s <code>\/etc\/resolv.conf<\/code> points to Docker&#8217;s embedded DNS server at <code>127.0.0.11<\/code>. When the app looks up a name, the embedded server first checks container names, service names and aliases on the same network. If the name is not a container, it forwards the query to the host&#8217;s normal DNS servers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Compose, every service name is a DNS name, and if a service has several replicas, the name returns all their IPs. You can set custom DNS servers with <code>--dns<\/code> if needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q65. How do you check which ports a container has published?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>docker port<\/code> for a quick answer, or <code>docker ps<\/code> and <code>docker inspect<\/code> for more detail.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker port api                     # e.g. 8080\/tcp -&gt; 0.0.0.0:8080\ndocker ps --format \"{{.Names}}: {{.Ports}}\"\ndocker inspect --format '{{json .NetworkSettings.Ports}}' api<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On the host, you can also use <code>ss -tlnp<\/code> to see which ports are listening.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Storage and Volume Docker Interview Questions with Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Containers lose their files when you delete them, so interviewers always ask how you keep data safe. These Docker interview questions cover volumes, bind mounts and running databases in containers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q66. Why is data inside a container lost when you remove it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A container&#8217;s files live in a thin writable layer on top of the read-only image layers. That writable layer belongs to the container. When you remove the container with <code>docker rm<\/code>, Docker deletes the layer, and every file written inside the container goes with it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Stopping and restarting a container keeps the layer, so data survives a restart. However, containers are meant to be thrown away and replaced, for example on every deploy. So any data you need to keep must go into a volume or an outside service, such as a managed database or object storage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q67. What is the difference between a volume and a bind mount?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Both put data outside the container&#8217;s writable layer, so it survives when the container is removed. The difference is who manages the folder.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Volume<\/th><th>Bind mount<\/th><\/tr><\/thead><tbody><tr><td>Managed by<\/td><td>Docker, in its own storage area<\/td><td>You, any host path<\/td><\/tr><tr><td>Created with<\/td><td><code>-v dbdata:\/data<\/code> or <code>--mount type=volume<\/code><\/td><td><code>-v \/home\/me\/app:\/app<\/code> or <code>--mount type=bind<\/code><\/td><\/tr><tr><td>Works the same on every host<\/td><td>Yes<\/td><td>Depends on the host path<\/td><\/tr><tr><td>Backup and move<\/td><td>Easy with Docker commands<\/td><td>Normal file tools<\/td><\/tr><tr><td>Best for<\/td><td>Database data, app data in production<\/td><td>Local development, config files<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So use volumes for data that must be kept safe, and bind mounts for sharing your source code with a container while you develop. The <code>--mount<\/code> syntax is longer but clearer, so many teams prefer it in scripts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q68. What is a tmpfs mount?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A tmpfs mount stores files in the host&#8217;s memory, not on disk. The data disappears when the container stops. It is fast and never written to disk.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --tmpfs \/tmp:size=64m shop-api:1.4.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use it for temporary files, caches and sensitive data that should never touch the disk, such as short-lived tokens. It also pairs well with a read-only root file system, because the app still needs somewhere to write temp files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q69. When should you use a named volume instead of a bind mount?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a named volume when the data belongs to the app and must stay safe, such as database files, uploaded files or queue data. Docker manages the folder, sets the right permissions and keeps it the same on every machine, so your Compose file works anywhere.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a bind mount when you want the container to see files from a specific place on your host. The main examples are your source code during development, so changes show up at once, and a config file you edit on the host.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q70. How do you back up and restore a Docker volume?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A simple and common way is to run a temporary container that mounts the volume and a host folder, then use <code>tar<\/code> to copy the data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Backup: pack the volume into a tar file in the current folder\ndocker run --rm -v dbdata:\/data -v \"$PWD\":\/backup alpine:3.22 \\\n  tar czf \/backup\/dbdata-backup.tgz -C \/data .\n\n# Restore: unpack the tar file into a (new) volume\ndocker run --rm -v dbdata:\/data -v \"$PWD\":\/backup alpine:3.22 \\\n  tar xzf \/backup\/dbdata-backup.tgz -C \/data<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For databases, stop writes first or use the database&#8217;s own tool, such as <code>pg_dump<\/code> for PostgreSQL. Copying the raw files of a running database can give you a broken backup.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q71. How do you share a volume between two containers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Mount the same named volume into both containers. Both see the same files, so one can write and the other can read.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker volume create shared-logs\ndocker run -d --name app -v shared-logs:\/var\/log\/app shop-api:1.4.0\ndocker run -d --name shipper -v shared-logs:\/logs:ro log-shipper:2.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here the log shipper mounts the volume read-only, so it cannot change the app&#8217;s files. Be careful when two containers write to the same files at once, because Docker does not lock files for you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q72. What is the writable container layer, and why should you avoid writing a lot to it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The writable layer is the top layer that each container gets on top of its image. Any file the app creates or changes goes there. It uses a copy-on-write storage driver, usually overlay2, so the first time a file from the image is changed, the whole file is copied up into the writable layer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So writing a lot there is slow, especially for big files, and it fills the host disk under Docker&#8217;s folder. The data is also lost when the container is removed. So write logs to stdout, and put heavy or important data in volumes or tmpfs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q73. How do you run a database like PostgreSQL in Docker without losing data?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Store the database files in a named volume mounted at the database&#8217;s data folder. Then you can stop, remove and recreate the container, and the data stays.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker volume create pgdata\ndocker run -d --name db \\\n  -e POSTGRES_PASSWORD=change-me \\\n  -v pgdata:\/var\/lib\/postgresql\/data \\\n  -p 127.0.0.1:5432:5432 \\\n  postgres:17<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Also, pin a major version tag such as <code>postgres:17<\/code>, because a newer major version cannot read old data files without an upgrade. Take regular backups with <code>pg_dump<\/code>. For production, many teams use a managed database instead, so backups and failover are handled for them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q74. How do you list and remove unused volumes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the <code>docker volume<\/code> commands. Volumes are never removed automatically, because Docker does not want to delete your data by accident.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker volume ls                       # list volumes\ndocker volume ls -f dangling=true      # volumes not used by any container\ndocker volume inspect pgdata           # where it lives and its labels\ndocker volume rm pgdata                # remove one volume\ndocker volume prune                    # remove unused anonymous volumes\ndocker volume prune -a                 # remove all unused volumes, named ones too<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Always check before pruning on a server, because a removed volume cannot be recovered.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q75. What does read-only mode (:ro) do for a mount?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Adding <code>:ro<\/code> (or <code>readonly<\/code> with <code>--mount<\/code>) makes the mount read-only inside the container. The app can read the files but not change or delete them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d -v \"$PWD\/config.yaml\":\/etc\/app\/config.yaml:ro shop-api:1.4.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It is a good safety habit for config files, certificates and shared data the container only needs to read. Even if the app has a bug or is attacked, it cannot change those files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Docker Compose Interview Questions with Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most teams run their local stack with Compose, so expect a few Docker interview questions about it, even for junior roles. A full example Compose file is in the hands-on section below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q76. What is Docker Compose, and when do you use it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker Compose is a tool to define and run many containers together from one YAML file, usually <code>compose.yaml<\/code>. The file lists your services, their images or build folders, ports, environment variables, networks and volumes. Then one command starts the whole stack.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker compose up -d      # start everything in the background\ndocker compose ps         # see the services\ndocker compose logs -f api\ndocker compose down       # stop and remove containers and the network<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You use it for local development, automated tests in CI, demos and small single-server deployments. For example, one file can start your Go API, PostgreSQL, Redis and a mail testing tool, so a new developer is ready in minutes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q77. What is the difference between docker compose and the old docker-compose command?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>docker-compose<\/code> (with a hyphen) was Compose V1, a separate tool written in Python. <code>docker compose<\/code> (with a space) is Compose V2, written in Go and built into the Docker CLI as a plugin. Compose V1 stopped getting updates in 2023, so always use <code>docker compose<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">V2 is faster, supports newer features like profiles, <code>watch<\/code> and better build support, and follows the open Compose Specification. Also, the top-level <code>version:<\/code> key in the file is now obsolete, so you can leave it out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q78. What are services, networks and volumes in a compose.yaml file?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These are the three main top-level sections of a Compose file.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>services:<\/strong> each service is one container (or several replicas), such as <code>api<\/code>, <code>db<\/code> or <code>cache<\/code>. You set its image or build, ports, environment and dependencies.<\/li>\n\n\n<li><strong>networks:<\/strong> the networks services join. If you do not define any, Compose creates one default network for the project, and every service can reach the others by service name.<\/li>\n\n\n<li><strong>volumes:<\/strong> named volumes for data that must survive, such as database files. Services mount them by name.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>services:\n  api:\n    build: .\n    networks: [backend]\n  db:\n    image: postgres:17\n    volumes:\n      - pgdata:\/var\/lib\/postgresql\/data\n    networks: [backend]\nnetworks:\n  backend:\nvolumes:\n  pgdata:<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q79. What does depends_on do, and why does it not wait for an app to be ready?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>depends_on<\/code> controls start and stop order. If <code>api<\/code> depends on <code>db<\/code>, Compose starts <code>db<\/code> first and stops it last. However, by default it only waits until the <code>db<\/code> container has started, not until PostgreSQL inside it is ready for connections, which can take several seconds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So your API might start, try to connect and fail. There are two fixes. Add a healthcheck to the database and use <code>condition: service_healthy<\/code>, as the next answer shows. Also, write your app to retry its connections with a short backoff, because in production a dependency can restart at any time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q80. How do you make one service wait until another is healthy?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Give the dependency a <code>healthcheck<\/code>, then use the long form of <code>depends_on<\/code> with <code>condition: service_healthy<\/code>. Compose then waits until the healthcheck passes before it starts the dependent service.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>services:\n  api:\n    build: .\n    depends_on:\n      db:\n        condition: service_healthy\n  db:\n    image: postgres:17\n    environment:\n      POSTGRES_PASSWORD: change-me\n    healthcheck:\n      test: [\"CMD-SHELL\", \"pg_isready -U postgres\"]\n      interval: 5s\n      timeout: 3s\n      retries: 10<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Another condition, <code>service_completed_successfully<\/code>, is useful for one-time jobs such as running database migrations before the API starts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q81. How do you pass environment variables and .env files to Compose?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are three common ways, and they do slightly different jobs.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>What it does<\/th><\/tr><\/thead><tbody><tr><td><code>environment:<\/code> in a service<\/td><td>Sets variables inside that container<\/td><\/tr><tr><td><code>env_file:<\/code> in a service<\/td><td>Loads variables for that container from a file<\/td><\/tr><tr><td><code>.env<\/code> file next to <code>compose.yaml<\/code><\/td><td>Fills <code>${VAR}<\/code> placeholders inside the Compose file itself<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>services:\n  api:\n    image: shop-api:${API_VERSION:-latest}   # from .env, with a default\n    environment:\n      LOG_LEVEL: info\n    env_file:\n      - api.env<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Keep real secrets out of Git, so add <code>.env<\/code> and <code>api.env<\/code> to <code>.gitignore<\/code>. Compose also supports <code>secrets:<\/code>, which mounts secret values as files under <code>\/run\/secrets<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q82. How do you scale a service in Compose?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the <code>--scale<\/code> flag, or set <code>deploy.replicas<\/code> in the file. Compose starts several containers of the same service, and the service name in DNS returns all of their IPs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker compose up -d --scale worker=4<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You cannot scale a service that publishes a fixed host port, such as <code>\"8080:8080\"<\/code>, because only one container can use that host port. So scale background workers freely, and for web services put a load balancer like nginx or Traefik in front.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q83. What are Compose profiles?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Profiles let you mark some services as optional. A service with a profile only starts when you turn that profile on. Services without a profile always start.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>services:\n  api:\n    build: .\n  db:\n    image: postgres:17\n  adminer:\n    image: adminer\n    profiles: [\"debug\"]   # only with --profile debug<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>docker compose up -d                   # api and db\ndocker compose --profile debug up -d   # api, db and adminer<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So one file can hold your normal stack plus extra tools for debugging, testing or monitoring.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q84. How do you rebuild and restart only one service?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Name the service at the end of the command. Compose then rebuilds and recreates only that one, and leaves the others running.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker compose up -d --build api     # rebuild the image and recreate api\ndocker compose restart api           # restart without rebuilding\ndocker compose up -d --no-deps api   # do not touch its dependencies<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For fast local development, <code>docker compose watch<\/code> can also sync file changes into a running container or rebuild it automatically when you save a file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q85. Is Docker Compose a good choice for production?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It depends on the size of the system. Compose works well in production for small apps on one server, such as an internal tool, a small website or a side project. It is simple, and with restart policies and healthchecks it is quite reliable.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, Compose runs on one host. It has no built-in failover across machines, no rolling updates across a cluster, no autoscaling and limited secret management. So for systems that need high availability or many servers, teams use an orchestrator such as Kubernetes or a managed service like AWS ECS. A common pattern is Compose for development and Kubernetes for production.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Security Docker Interview Questions with Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Security is where senior candidates stand out. So prepare these Docker interview questions with real examples, and always mention &#8220;least privilege&#8221;: give a container only what it needs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q86. Why should containers not run as root?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, the process in a container runs as root (user ID 0). Root inside a container is limited, but it is still the same user ID as root on the host. If an attacker breaks into your app and then finds a kernel bug or a bad setting, such as a mounted host folder, root makes it much easier to damage the host.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So run as a normal user. Add a <code>USER<\/code> line in the Dockerfile, use a <code>nonroot<\/code> base image, or pass <code>--user 10001:10001<\/code> on <code>docker run<\/code>. In Kubernetes, set <code>runAsNonRoot: true<\/code> in the security context.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q87. What is rootless Docker mode?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In rootless mode, the Docker daemon itself and all containers run as a normal, non-root user on the host. It uses user namespaces, so &#8220;root&#8221; inside a container maps to an unprivileged user outside.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So even if an attacker escapes a container, they only get the rights of a normal user, not root on the host. There are some limits, such as publishing ports below 1024 needs extra setup, and some storage and network features work differently. Podman also runs rootless by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q88. What are Linux capabilities, and how do you drop them?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Linux splits root&#8217;s powers into small pieces called capabilities, such as <code>NET_BIND_SERVICE<\/code> (use ports below 1024), <code>NET_ADMIN<\/code> (change network settings) and <code>SYS_ADMIN<\/code> (many admin actions). Docker gives containers a reduced default set, but you can remove even more.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The safest pattern is to drop all capabilities, then add back only what the app needs.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --cap-drop ALL --cap-add NET_BIND_SERVICE -p 80:80 web:1.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Most Go web services need no capabilities at all, especially when they listen on a port above 1024 such as 8080.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q89. What does &#8211;privileged do, and why is it dangerous?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>--privileged<\/code> gives a container almost all the powers of the host. It gets every capability, access to all host devices, and most security filters such as seccomp and AppArmor are turned off. In practice, a privileged container can easily take over the host.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So never use it for normal apps. It is only for special cases such as running Docker inside Docker or low-level system tools. Even then, prefer giving only the exact capability or device needed with <code>--cap-add<\/code> or <code>--device<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q90. Why is mounting the Docker socket into a container risky?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Mounting <code>\/var\/run\/docker.sock<\/code> lets the container talk to the Docker daemon. With that, it can start a new privileged container that mounts the host&#8217;s root folder, which means full control of the host. So the socket is as powerful as root access.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Tools like CI runners, monitoring agents and reverse proxies sometimes ask for it. Avoid it where you can. Use a rootless or remote builder for CI, use a socket proxy that allows only read-only API calls, and never mount the socket into internet-facing apps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q91. How do you scan an image for known vulnerabilities?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An image scanner reads the packages inside an image and checks them against databases of known security issues (CVEs). Popular tools are Docker Scout, Trivy and Grype, and most cloud registries can scan images on push.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker scout cves shop-api:1.4.0\ntrivy image shop-api:1.4.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run scans in CI and fail the build for critical issues that have a fix. Then fix them by updating the base image and dependencies. Small base images like distroless have far fewer packages, so they show far fewer issues to begin with. For Go code, also run <code>govulncheck<\/code>, which only reports issues in code your program really calls.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q92. How do you keep secrets out of images and environment variables?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Never put secrets in the Dockerfile with <code>ENV<\/code>, <code>ARG<\/code> or <code>COPY<\/code>, because they stay in the image layers and history, and anyone who pulls the image can read them. Also, add <code>.env<\/code> and key files to <code>.dockerignore<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>At build time:<\/strong> use BuildKit secret mounts (<code>RUN --mount=type=secret<\/code>) or SSH mounts.<\/li>\n\n\n<li><strong>At run time:<\/strong> mount secrets as files from a secret store, such as Docker or Compose secrets, Kubernetes Secrets, AWS Secrets Manager or Vault.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Environment variables are better than baking secrets in, but they can leak through <code>docker inspect<\/code>, crash reports and child processes. So mounted files with tight permissions are safer for passwords and keys.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q93. What is a read-only root file system, and how do you enable it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With a read-only root file system, the container cannot change any file in its image. If an attacker gets in, they cannot drop new tools or change your binary. Use <code>--read-only<\/code>, and add a tmpfs for folders the app must write to.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --read-only --tmpfs \/tmp shop-api:1.4.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In Kubernetes, the same setting is <code>readOnlyRootFilesystem: true<\/code>. It works very well with Go apps, which usually write nothing to disk except temp files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q94. What are image signing and provenance, and why do they matter?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Image signing adds a cryptographic signature to an image, so you can check it really came from your team and was not changed. Sigstore Cosign is the most common tool today. Provenance is a signed record of how the image was built: which source commit, which builder and which steps. An SBOM (software bill of materials) lists every package inside the image.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They matter because of supply chain attacks, where an attacker swaps or changes an image in a registry. BuildKit can add provenance and SBOM attestations with <code>docker buildx build --provenance=true --sbom=true<\/code>, and Kubernetes admission controllers can refuse images that are not signed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q95. How do seccomp and AppArmor profiles protect containers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Seccomp filters which system calls (requests to the kernel) a container can make. Docker&#8217;s default seccomp profile blocks dozens of risky calls, such as loading kernel modules or changing the system clock. AppArmor (on Ubuntu and Debian) and SELinux (on Red Hat systems) control which files and resources a process can access.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker turns on the default seccomp profile and, where available, a default AppArmor profile automatically. You can apply stricter custom profiles for sensitive apps. So never disable them with <code>--security-opt seccomp=unconfined<\/code> unless you have a clear reason.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advanced and Scenario Docker Interview Questions with Answers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Senior rounds turn these ideas into real problems. For each scenario, explain what you would check first, and why, because interviewers care about your steps as much as the answer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q96. A container exits right after it starts. How do you find out why?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow these steps in order.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, read the logs with <code>docker logs &lt;name&gt;<\/code>. Most crashes print an error, such as a missing config value or a failed database connection.<\/li>\n\n\n<li>Next, check the exit code and details with <code>docker inspect --format '{{.State.ExitCode}} {{.State.Error}}' &lt;name&gt;<\/code>.<\/li>\n\n\n<li>Then check what command actually ran with <code>docker inspect --format '{{.Config.Entrypoint}} {{.Config.Cmd}}' &lt;name&gt;<\/code>.<\/li>\n\n\n<li>If needed, start the image with a shell instead of the app: <code>docker run -it --entrypoint sh &lt;image&gt;<\/code>, and run the command by hand.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Common causes are a wrong <code>CMD<\/code> or <code>ENTRYPOINT<\/code>, a missing environment variable, a binary built for the wrong CPU (<code>exec format error<\/code>), a missing file or library, or a process that runs in the background and leaves PID 1 with nothing to do.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q97. Your image is 1.2 GB. How do you bring it under 50 MB?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, look at where the size comes from with <code>docker history<\/code> or the <code>dive<\/code> tool. Usually the base image, build tools and caches take most of the space. Then apply these steps.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Use a multi-stage build, so the compiler and source code stay in the build stage.<\/li>\n\n\n<li>Copy only the final binary or build output into the last stage.<\/li>\n\n\n<li>Use a small runtime base, such as distroless, Alpine or scratch.<\/li>\n\n\n<li>Add a <code>.dockerignore<\/code> file so <code>.git<\/code>, <code>node_modules<\/code> and test data are not copied.<\/li>\n\n\n<li>Remove package caches in the same <code>RUN<\/code> line, and skip recommended packages.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">For a Go service, a static binary in <code>distroless\/static<\/code> or <code>scratch<\/code> usually ends up between 10 and 30 MB. For Node.js or Python, a slim base plus production-only dependencies often gets close to the target.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q98. A build is slow because the cache breaks every time. What do you check?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The cache breaks from the first instruction whose input changed, so find that line. Run the build with <code>--progress=plain<\/code> and look for the first step that is not <code>CACHED<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then check these common causes.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>COPY . .<\/code> comes before the dependency download, so any code change re-downloads everything.<\/li>\n\n\n<li>There is no <code>.dockerignore<\/code>, so changing files like <code>.git<\/code> or logs changes the build context.<\/li>\n\n\n<li>A build argument with a changing value, such as a timestamp or commit ID, is used early.<\/li>\n\n\n<li><code>RUN apt-get update<\/code> uses a base image tag that moves, such as <code>latest<\/code>.<\/li>\n\n\n<li>In CI, every job starts on a fresh machine with no cache. Use <code>--cache-from<\/code> and <code>--cache-to<\/code> with a registry or the CI cache.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Also, use BuildKit cache mounts for package managers, so even rebuilt layers reuse downloads.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q99. Two containers cannot talk to each other. How do you debug it?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go from the network to the app, one step at a time.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, check they are on the same user-defined network: <code>docker network inspect &lt;network&gt;<\/code>. Containers on the default bridge cannot use names.<\/li>\n\n\n<li>Next, check the name resolves. From one container, run <code>nslookup db<\/code> or <code>getent hosts db<\/code>, or use a debug container such as <code>nicolaka\/netshoot<\/code>.<\/li>\n\n\n<li>Then check the port is open: <code>nc -zv db 5432<\/code>.<\/li>\n\n\n<li>Check the app listens on <code>0.0.0.0<\/code>, not <code>127.0.0.1<\/code>. An app bound to localhost inside its container cannot be reached from other containers.<\/li>\n\n\n<li>Finally, check you use the container port, not the published host port, and look for firewall rules or a wrong host name in the config.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>127.0.0.1<\/code> mistake is the most common one in interviews and in real life.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q100. A container uses too much memory and gets killed. How do you set and check limits?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, confirm it was killed for memory. <code>docker inspect --format '{{.State.OOMKilled}}' &lt;name&gt;<\/code> shows <code>true<\/code>, and the exit code is usually 137. Then watch live usage with <code>docker stats<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set a limit with <code>--memory<\/code>, so one container cannot take memory from the others.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --memory 512m --memory-swap 512m shop-api:1.4.0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then find the real cause. The app might have a leak, a cache with no size limit, or a runtime that does not know about the container limit. For Go, set <code>GOMEMLIMIT<\/code> a little below the container limit, such as <code>GOMEMLIMIT=450MiB<\/code>, so the garbage collector works harder before the kernel kills the process. Use pprof to find the leak.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q101. What does exit code 137 mean, and what does exit code 143 mean?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a process is ended by a signal, the exit code is 128 plus the signal number. So the code tells you which signal stopped it.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Exit code<\/th><th>Signal<\/th><th>Usual meaning<\/th><\/tr><\/thead><tbody><tr><td>0<\/td><td>None<\/td><td>Finished normally<\/td><\/tr><tr><td>1<\/td><td>None<\/td><td>App error, check the logs<\/td><\/tr><tr><td>137<\/td><td>SIGKILL (9)<\/td><td>Killed: out of memory, or <code>docker kill<\/code>, or stop timeout<\/td><\/tr><tr><td>139<\/td><td>SIGSEGV (11)<\/td><td>Crash from bad memory access<\/td><\/tr><tr><td>143<\/td><td>SIGTERM (15)<\/td><td>Asked to stop, normal for <code>docker stop<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So 143 is usually fine, while 137 needs checking. Look at <code>OOMKilled<\/code> first, then at how long the app takes to shut down.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q102. How do you set CPU and memory limits on a container?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use flags on <code>docker run<\/code>, or the <code>deploy.resources<\/code> section in Compose.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 512 MB memory, 1.5 CPU cores, at most 200 processes\ndocker run -d --memory 512m --cpus 1.5 --pids-limit 200 shop-api:1.4.0<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>services:\n  api:\n    image: shop-api:1.4.0\n    deploy:\n      resources:\n        limits:\n          cpus: \"1.5\"\n          memory: 512M<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A memory limit is hard: going over it gets the process killed. A CPU limit only slows the container down (throttling). Since Go 1.25, the Go runtime reads the container CPU limit and sets <code>GOMAXPROCS<\/code> to match, which avoids heavy throttling.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q103. How do you collect logs from many containers in production?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, make every app log to stdout and stderr, ideally as JSON with fields like level, request ID and service name. Docker captures this through a logging driver. The default <code>json-file<\/code> driver writes to files on the host, so turn on log rotation, or the disk will fill up.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"log-driver\": \"json-file\",\n  \"log-opts\": { \"max-size\": \"10m\", \"max-file\": \"3\" }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then ship the logs to a central system. You can use a logging driver such as <code>fluentd<\/code>, <code>gelf<\/code> or <code>awslogs<\/code>, or run an agent such as Fluent Bit, Vector or Grafana Alloy that reads the log files. Store and search them in Loki, Elasticsearch or a cloud service like CloudWatch.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q104. How would you update a running service with zero downtime?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On a single host with plain Docker, you start the new version next to the old one, check it is healthy, switch traffic, then stop the old one.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Build and push a new image with a new version tag.<\/li>\n\n\n<li>Start a new container from it on the same network, without stopping the old one.<\/li>\n\n\n<li>Wait until its healthcheck passes.<\/li>\n\n\n<li>Point the reverse proxy (nginx, Traefik or Caddy) at the new container and reload it.<\/li>\n\n\n<li>Stop the old container gracefully with <code>docker stop<\/code>, so it finishes in-flight requests.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The app must handle SIGTERM and finish requests before exiting. In real production, an orchestrator such as Kubernetes or ECS does these rolling updates for you, using readiness probes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q105. How do you copy files in and out of a running container?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>docker cp<\/code>. It works in both directions and also works with stopped containers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker cp api:\/app\/logs\/error.log .\/error.log    # container to host\ndocker cp .\/config.yaml api:\/etc\/app\/config.yaml  # host to container<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It is handy for debugging, such as pulling out a crash dump or a profile. However, do not use it to deploy or change apps. Files copied into a container are lost when it is recreated, so build them into the image or mount them instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q106. Your app works locally but fails inside Docker with a time zone or TLS error. Why?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Small base images, such as scratch and some distroless or Alpine images, may not include two things your laptop has: time zone data and CA certificates.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Time zone error:<\/strong> the app cannot load a zone like <code>Asia\/Kolkata<\/code>, because <code>\/usr\/share\/zoneinfo<\/code> is missing. In Go, add <code>import _ \"time\/tzdata\"<\/code> or build with <code>-tags timetzdata<\/code> to embed the data in the binary, or install the <code>tzdata<\/code> package.<\/li>\n\n\n<li><strong>TLS error:<\/strong> HTTPS calls fail with &#8220;certificate signed by unknown authority&#8221;, because <code>\/etc\/ssl\/certs<\/code> is missing. Copy the CA certificates from the build stage, or use a base image such as <code>distroless\/static<\/code> that already includes them.<\/li>\n\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM scratch\nCOPY --from=build \/etc\/ssl\/certs\/ca-certificates.crt \/etc\/ssl\/certs\/\nCOPY --from=build \/app \/app\nENTRYPOINT [\"\/app\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q107. How do you debug a container image that has no shell, such as distroless?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You cannot <code>docker exec<\/code> into it, because there is no shell. Instead, start a separate debug container that shares the target&#8217;s namespaces, so you can see its processes and network with your own tools.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Share the network and process namespaces of the \"api\" container\ndocker run -it --rm \\\n  --network container:api \\\n  --pid container:api \\\n  nicolaka\/netshoot<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Docker Desktop also has a <code>docker debug<\/code> command that attaches a toolbox shell to any container. In Kubernetes, use <code>kubectl debug<\/code> with an ephemeral container. Another option is a <code>:debug<\/code> image variant, as distroless offers, for testing only.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q108. How do Docker and Kubernetes work together today?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker and Kubernetes do different jobs. Docker is mainly used to build images and run containers on one machine, especially for development and CI. Kubernetes runs containers across a cluster of machines, with scaling, self-healing, rolling updates and service discovery.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The common flow is: developers build an image with Docker, CI pushes it to a registry, and Kubernetes pulls and runs it on its nodes using containerd or CRI-O. Because the image follows the OCI standard, it runs the same everywhere. Our <a href=\"https:\/\/smitabharat.com\/blog\/kubernetes-interview-questions\/\">Kubernetes interview questions<\/a> cover the cluster side in detail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q109. Why did Kubernetes remove dockershim, and can you still use Docker images in Kubernetes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes talks to container runtimes through a standard interface called CRI (Container Runtime Interface). Docker Engine was created before CRI and never supported it, so Kubernetes kept an adapter called dockershim. Keeping that extra layer was costly, so it was removed in Kubernetes 1.24.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, you can still use Docker images. They are standard OCI images, so containerd and CRI-O run them without any change. Only clusters that used Docker Engine as the node runtime had to switch, and teams that still need it can use the separate <code>cri-dockerd<\/code> adapter.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q110. Docker Swarm or Kubernetes: which would you pick for a new project, and why?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Docker Swarm is Docker&#8217;s built-in orchestrator. It is much simpler to learn and set up, uses the same Compose-style files and is fine for small clusters. Kubernetes is more complex, but it has a far larger ecosystem, more features and support from every major cloud as a managed service (EKS, GKE, AKS).<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Docker Swarm<\/th><th>Kubernetes<\/th><\/tr><\/thead><tbody><tr><td>Learning curve<\/td><td>Low<\/td><td>High<\/td><\/tr><tr><td>Setup<\/td><td>One command per node<\/td><td>More work, or use a managed service<\/td><\/tr><tr><td>Ecosystem and tools<\/td><td>Small<\/td><td>Very large<\/td><\/tr><tr><td>Autoscaling<\/td><td>Not built in<\/td><td>Built in (HPA, cluster autoscaler)<\/td><\/tr><tr><td>Cloud managed options<\/td><td>Few<\/td><td>Every major cloud<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For most new projects, I would pick a managed Kubernetes service, because of its ecosystem and the skills available in the job market. For a small team running a few services on one or two servers, Docker Compose or Swarm can be enough and much simpler.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Hands-On Docker Interview Questions Practice<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Interviewers often ask you to write a Dockerfile on the spot. Here is a clean multi-stage Dockerfile for a small Go web service. It answers questions 26, 27, 35, 38 and 47 in one go.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Stage 1: build the Go binary with all build tools\nFROM golang:1.27 AS build\nWORKDIR \/src\n\n# Copy dependency files first so this layer stays cached\nCOPY go.mod go.sum .\/\nRUN go mod download\n\n# Now copy the rest of the code and build a static binary\nCOPY . .\nRUN CGO_ENABLED=0 go build -o \/app .\/cmd\/api\n\n# Stage 2: tiny runtime image with no shell and a non-root user\nFROM gcr.io\/distroless\/static-debian12:nonroot\nCOPY --from=build \/app \/app\nEXPOSE 8080\nUSER nonroot:nonroot\nENTRYPOINT [\"\/app\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first stage downloads modules before copying the code, so code changes do not break the module cache. The second stage keeps only the binary, so the final image is usually under 20 MB. <code>CGO_ENABLED=0<\/code> makes a static binary that needs no C libraries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, here is a small Compose file with an API and a PostgreSQL database. It answers questions 78 to 81.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># compose.yaml: run the API and its database together\nservices:\n  api:\n    build: .\n    ports:\n      - \"8080:8080\"          # host port 8080 -&gt; container port 8080\n    environment:\n      DATABASE_URL: postgres:\/\/app:secret@db:5432\/shop?sslmode=disable\n    depends_on:\n      db:\n        condition: service_healthy   # wait until the database is ready\n  db:\n    image: postgres:17\n    environment:\n      POSTGRES_USER: app\n      POSTGRES_PASSWORD: secret\n      POSTGRES_DB: shop\n    volumes:\n      - dbdata:\/var\/lib\/postgresql\/data   # named volume keeps data safe\n    healthcheck:\n      test: [\"CMD-SHELL\", \"pg_isready -U app -d shop\"]\n      interval: 5s\n      retries: 5\nvolumes:\n  dbdata:<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The API reaches the database by its service name, db, because Compose puts both services on one network. The healthcheck plus <code>condition: service_healthy<\/code> fixes the classic depends_on problem from question 79. In real projects, load the password from a secret instead of writing it in the file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, these are the commands you should be able to type without looking them up.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker build -t shop-api:1.0 .          # build an image from the Dockerfile\ndocker images                           # list local images\ndocker run -d --name api -p 8080:8080 shop-api:1.0   # run in the background\ndocker ps -a                            # list all containers\ndocker logs -f api                      # follow the logs\ndocker exec -it api sh                  # open a shell (if the image has one)\ndocker inspect api                      # full details, exit code, IPs\ndocker stats                            # live CPU and memory use\ndocker compose up -d --build            # start the whole stack\ndocker system prune                     # remove stopped containers and unused data<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes in Docker Interview Questions<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Mixing up image and container:<\/strong> always say &#8220;an image is the template, a container is the running copy&#8221;.<\/li>\n\n\n<li><strong>Saying EXPOSE publishes a port:<\/strong> it does not; only -p or a Compose ports entry does.<\/li>\n\n\n<li><strong>Forgetting about PID 1:<\/strong> if your app ignores SIGTERM, every stop takes the full timeout.<\/li>\n\n\n<li><strong>Using latest in production:<\/strong> pin a version tag or a digest so deploys are repeatable.<\/li>\n\n\n<li><strong>Putting secrets in ENV or ARG:<\/strong> they end up in the image history for anyone to read.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Answering Docker Interview Questions<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Start with a one-line definition,<\/strong> then add one real example from a project.<\/li>\n\n\n<li><strong>Draw the flow<\/strong> of Dockerfile, image, registry and container if you have a whiteboard.<\/li>\n\n\n<li><strong>Mention trade-offs,<\/strong> such as Alpine being small but using musl.<\/li>\n\n\n<li><strong>Talk about security by default:<\/strong> non-root users, small images and image scanning.<\/li>\n\n\n<li><strong>Link Docker to Kubernetes,<\/strong> because most teams use both together.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To practise these Docker interview questions, take any small app you have and write a multi-stage Dockerfile for it. Then measure the image size with docker images, add a .dockerignore file and a non-root user, and measure again. Hint: try both a slim base image and distroless, and compare the sizes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/docs.docker.com\/get-started\/docker-overview\/\">Docker overview in the Docker docs<\/a><\/li>\n\n\n<li><a href=\"https:\/\/docs.docker.com\/build\/building\/multi-stage\/\">Multi-stage builds in the Docker docs<\/a><\/li>\n\n\n<li><a href=\"https:\/\/docs.docker.com\/compose\/\">Docker Compose documentation<\/a><\/li>\n\n\n<li><a href=\"https:\/\/docs.docker.com\/reference\/dockerfile\/\">Dockerfile reference<\/a><\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Docker interview questions focus on images, containers, networks, volumes and security.<\/li>\n\n\n<li>An image is a read-only template, and a container is a running copy of it.<\/li>\n\n\n<li>Multi-stage builds, small base images and .dockerignore keep images small.<\/li>\n\n\n<li>Use user-defined networks for name-based DNS, and volumes for data that must survive.<\/li>\n\n\n<li>Run as non-root, keep secrets out of images, and pin image versions.<\/li>\n\n\n<li>Every one of the 110 questions now has a full answer, with commands you can try.<\/li>\n\n\n<li>Practise the hands-on Dockerfile and Compose file, because live tasks are common.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Containers are only half the story in most interviews. Next, read <a href=\"https:\/\/smitabharat.com\/blog\/kubernetes-interview-questions\/\">Kubernetes interview questions<\/a>, with pods, deployments, services, scaling and real cluster scenarios. For more question lists, browse the <a href=\"https:\/\/smitabharat.com\/blog\/go-interview-questions-hub\/\">Go interview questions hub<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker interview questions come up in almost every backend, DevOps and cloud interview today, because nearly every team ships its apps in containers. This&hellip;<\/p>\n","protected":false},"author":1,"featured_media":920,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[10],"tags":[128,127,125,77,126],"swapz_series":[],"class_list":["post-923","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interview","tag-containers","tag-devops","tag-docker","tag-intermediate","tag-interview-questions"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Docker Interview Questions: Most Asked with Answers<\/title>\n<meta name=\"description\" content=\"Docker interview questions with full answers, basic to advanced: images, Dockerfile, networking, volumes, Compose, security and real scenarios.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Docker Interview Questions: Most Asked with Answers\" \/>\n<meta property=\"og:description\" content=\"Docker interview questions with full answers, basic to advanced: images, Dockerfile, networking, volumes, Compose, security and real scenarios.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-11T05:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-24T05:38:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"63 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Docker Interview Questions: 110 Most Asked, with Full Answers\",\"datePublished\":\"2026-10-11T05:30:00+00:00\",\"dateModified\":\"2026-10-24T05:38:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/\"},\"wordCount\":10946,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/docker-interview-questions-featured.png\",\"keywords\":[\"Containers\",\"DevOps\",\"Docker\",\"Intermediate\",\"Interview Questions\"],\"articleSection\":[\"Interview\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/\",\"name\":\"Docker Interview Questions: Most Asked with Answers\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/docker-interview-questions-featured.png\",\"datePublished\":\"2026-10-11T05:30:00+00:00\",\"dateModified\":\"2026-10-24T05:38:27+00:00\",\"description\":\"Docker interview questions with full answers, basic to advanced: images, Dockerfile, networking, volumes, Compose, security and real scenarios.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/docker-interview-questions-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/docker-interview-questions-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Docker Interview Questions featured image: topics from images to production\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/docker-interview-questions\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Docker Interview Questions: 110 Most Asked, with Full Answers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Docker Interview Questions: Most Asked with Answers","description":"Docker interview questions with full answers, basic to advanced: images, Dockerfile, networking, volumes, Compose, security and real scenarios.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"Docker Interview Questions: Most Asked with Answers","og_description":"Docker interview questions with full answers, basic to advanced: images, Dockerfile, networking, volumes, Compose, security and real scenarios.","og_url":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-10-11T05:30:00+00:00","article_modified_time":"2026-10-24T05:38:27+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"63 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Docker Interview Questions: 110 Most Asked, with Full Answers","datePublished":"2026-10-11T05:30:00+00:00","dateModified":"2026-10-24T05:38:27+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/"},"wordCount":10946,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-featured.png","keywords":["Containers","DevOps","Docker","Intermediate","Interview Questions"],"articleSection":["Interview"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/","url":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/","name":"Docker Interview Questions: Most Asked with Answers","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-featured.png","datePublished":"2026-10-11T05:30:00+00:00","dateModified":"2026-10-24T05:38:27+00:00","description":"Docker interview questions with full answers, basic to advanced: images, Dockerfile, networking, volumes, Compose, security and real scenarios.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/docker-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/docker-interview-questions-featured.png","width":2400,"height":1260,"caption":"Docker Interview Questions featured image: topics from images to production"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/docker-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Docker Interview Questions: 110 Most Asked, with Full Answers"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/923","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=923"}],"version-history":[{"count":1,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/923\/revisions"}],"predecessor-version":[{"id":963,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/923\/revisions\/963"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/920"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=923"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}