DevOps.Academy
CoursesCurriculumInterview prepPricing
◔My learningSign in
DevOps.Academy

Free, hands-on DevOps lessons. Made with care in India.

System status

Learn

All coursesLinux roadmapCurriculumInterview questionsCheat sheetsMy learning

Academy

PricingCertificates

Legal

PrivacyTermsContact

devops.rajeev.pro

Docker · interview practice

Docker interview questions

Answer each one out loud first, then tap it to check yourself against a model answer and the lesson behind it.

Introduction 2Under the hood 2Installation 2Docker basics 2Third-party images 2Data persistence 2Building images 2Registries 2Running containers 2Networking 2Security 2Docker CLI 1Developer experience 1Deploying containers 1

Introduction

Q1A developer says a service only runs on their laptop. What does a container help make repeatable?junior

A container image packages the application with its runtime and dependencies, so the same image can be run in development, CI and production. It does not guarantee identical behavior if external configuration or services differ.

Read the lesson: Containers: what they are and why they won →
Q2How does a container differ from a virtual machine at the kernel boundary?junior

A container isolates processes while sharing the host kernel. A virtual machine runs a guest operating system and its own kernel on virtual hardware, so it has a different isolation and resource model.

Read the lesson: Containers: what they are and why they won →

Under the hood

Q3Which Linux mechanisms give a container its own process and network views?junior

Namespaces isolate views such as process IDs, networking, mounts and hostnames. They do not by themselves limit resource consumption; cgroups handle resource accounting and limits.

Read the lesson: Under the hood: namespaces, cgroups and layered filesystems →
Q4A container exceeds its memory limit. Which kernel mechanism enforces that limit?junior

The container runtime configures cgroups to account for and constrain resources such as memory and CPU. Namespaces affect what the process can see, not how much CPU or memory it can consume.

Read the lesson: Under the hood: namespaces, cgroups and layered filesystems →

Installation

Q5When you run docker run, which component performs the request after the CLI?junior

The Docker CLI sends the request to the Docker daemon, which works with containerd and runc to create and start the container. The CLI itself does not create the container process.

Read the lesson: Installing Docker: Desktop, Engine on Linux, and rootless →
Q6Why is access to the Docker socket treated as highly privileged on a Linux host?junior

A user who can control the daemon can often start a container with access to host files and capabilities, which can amount to root-level control. I grant socket access only to trusted users and consider rootless mode where it fits.

Read the lesson: Installing Docker: Desktop, Engine on Linux, and rootless →

Docker basics

Q7What is the difference between an image and a container?junior

An image is the packaged, read-only filesystem and default command used to start workloads. A container is a running or stopped instance with its own writable layer and process state.

Read the lesson: Docker basics: images, containers, ports, logs and exec →
Q8A container is running but you need to inspect its output and shell. Which Docker commands help?junior

I use docker logs to read its standard output and error, then docker exec to run a command inside a running container. I use exec for diagnosis, not as a substitute for changing the image or deployment configuration.

Read the lesson: Docker basics: images, containers, ports, logs and exec →

Third-party images

Q9Before running a third-party image, what do you check beyond its name?junior

I check its publisher, documentation, required configuration, supported tags and security history. For a release I prefer a trusted source and a digest when I need the exact image content to stay fixed.

Read the lesson: Other people's images: databases, tools and runtimes →
Q10A database container starts, but the application connects before the database is ready. What should the startup logic do?junior

The application should retry the connection with a bounded backoff or wait on a meaningful readiness check. Container start order alone does not prove that the database is ready to accept queries.

Read the lesson: Other people's images: databases, tools and runtimes →

Data persistence

Q11A container holding database data is recreated. How do you keep the data?mid

I store database files in a Docker volume or an explicitly managed bind mount rather than only in the container writable layer. I also verify backups and restore procedures because persistence is not the same as backup.

Read the lesson: Keeping data: volumes, bind mounts and backups →
Q12How would you back up a Dockerized database so you can prove recovery works?mid

I use the database's dump mechanism to create a consistent backup, store it outside the container, and test restoring it into a clean instance. Copying a live data directory alone may not produce a consistent backup.

Read the lesson: Keeping data: volumes, bind mounts and backups →

Building images

Q13Why does Dockerfile instruction order affect rebuild time?mid

Docker can reuse cached layers when the instruction and its inputs have not changed. I copy stable dependency manifests and install dependencies before frequently changed source so source edits do not invalidate the dependency layer.

Read the lesson: Building images: Dockerfiles, the layer cache and multi-stage builds →
Q14What problem does a multi-stage Docker build solve?mid

It lets one stage compile or prepare the application while a later stage contains only the runtime files it needs. That can reduce the final image and avoid shipping build tools that are not needed at runtime.

Read the lesson: Building images: Dockerfiles, the layer cache and multi-stage builds →

Registries

Q15A release must deploy exactly the image that passed CI. How do you identify that image reliably?mid

I record and deploy the image digest, which identifies the immutable manifest content. A tag is useful for humans but can be moved to a different image later.

Read the lesson: Registries: Docker Hub, GHCR, ECR and tags you can trust →
Q16What does docker push require before it can upload an image to a registry?mid

The image needs a registry-qualified name and tag, and the client must be authenticated with permission to write there. I verify the tag points at the intended build before pushing.

Read the lesson: Registries: Docker Hub, GHCR, ECR and tags you can trust →

Running containers

Q17A service container exits unexpectedly. Which runtime settings help it recover without hiding the underlying issue?mid

I choose a restart policy appropriate for the service and configure resource limits and logging deliberately. I still inspect exit status and logs; an automatic restart can keep a broken process cycling.

Read the lesson: Running containers well: restart policies, limits, config and Compose →
Q18Why should environment-specific configuration be supplied outside the image?mid

The same image can then move through environments without rebuilding, while configuration remains explicit at runtime. Sensitive values should use an appropriate secret mechanism rather than being baked into image layers.

Read the lesson: Running containers well: restart policies, limits, config and Compose →

Networking

Q19Two containers on a user-defined Docker network need to communicate. What should they use for discovery?mid

They can use Docker's embedded DNS to resolve each other by container or service name on that network. This avoids hard-coding container IP addresses that can change when containers are recreated.

Read the lesson: Networking: bridge networks, published ports and container DNS →
Q20What is the difference between a container port and a published host port?mid

A container port is where the process listens inside its network namespace. Publishing maps a host port to that container port so clients outside the Docker network can reach it.

Read the lesson: Networking: bridge networks, published ports and container DNS →

Security

Q21A vulnerability scan reports many findings in the base image. What is a practical first response?senior

I identify which findings affect packages in the image and update to a supported, patched base image, then rebuild and scan again. I avoid suppressing findings without a reason and an owner.

Read the lesson: Container security: scanning, non-root, runtime limits and secrets →
Q22Why run an application as a non-root user inside its container?senior

If the process is compromised, a non-root UID reduces its privileges within the container. I also check file ownership and writable paths so the application still works without broad permissions.

Read the lesson: Container security: scanning, non-root, runtime limits and secrets →

Docker CLI

Q23Disk usage is growing on a Docker host. How do you investigate before pruning?senior

I inspect docker system df and list containers, images, volumes and networks to identify what is consuming space and whether it is still needed. I do not prune volumes blindly because they may contain persistent application data.

Read the lesson: The Docker CLI day to day: inspect, filter, format and clean up →

Developer experience

Q24A developer changes a dependency manifest while using Compose Watch. Which type of update should the workflow perform?senior

A dependency-manifest change usually requires rebuilding the image so the new dependency is installed. A source-only change may be synchronized or trigger a different action, depending on the service's watch rules.

Read the lesson: Developing with Docker: hot reload, debugging, tests and CI →

Deploying containers

Q25What should remain invariant when moving the same containerized service between a PaaS, Swarm and Kubernetes?senior

The application should remain in the same tested image, with configuration and secrets supplied at runtime and health behavior defined clearly. The platform-specific deployment and networking configuration will still differ.

Read the lesson: Deploying containers: PaaS, Docker Swarm and Kubernetes →
← Back to the Docker course