Day 19 - Docker Interview Q&A
Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
Search for a command to run...
Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
No comments yet. Be the first to comment.
1. Difference between Docker and Kubernetes Docker → Builds and runs containers.Kubernetes → Orchestrates containers across multiple nodes. Key points: Docker = container runtime. Kubernetes = container orchestration tool. Kubernetes provides auto...
In this session, we learn how to monitor a Kubernetes cluster using Prometheus and Grafana.This is not just theory — there is a GitHub repository containing all installation commands and demo steps.The repo will also be enhanced later with advanced K...
1. What is a ConfigMap in Kubernetes? A ConfigMap is used to store non-sensitive configuration data that your application needs — such as: Database port Connection type Any general configuration values In normal applications (non-Kubernetes), de...
Kubernetes normally supports built-in resources like: Deployment Service Pod ConfigMap Secret Ingress These are called native resources. Sometimes companies (Istio, ArgoCD, Prometheus Operator, Kyverno, etc.) want to add new features that Kub...
1. Why Kubernetes Services Are Needed When a Pod is created in Kubernetes, it receives a dynamic IP address.If the Pod dies and restarts, its IP changes.So other Pods (like checkout → payments) cannot rely on Pod IP because it changes, creating issue...
Answer:
Docker is an open-source containerization platform used to build, package, and run applications inside lightweight, portable containers. It helps manage the entire lifecycle of containers — building images, running containers, pushing/pulling images from registries, etc.
You can add:
“In my projects, I use Docker to write Dockerfiles, build images, run containers, optimize image size, and push artifacts to registries like Docker Hub/ECR.”
Answer:
| Containers | Virtual Machines |
| Lightweight | Heavyweight |
| Share the host OS kernel | Have full guest OS |
| Start in milliseconds | Start in minutes |
| Only need application + dependencies | Need OS + kernel + libraries |
| Image size is small (MBs) | Large images (GBs) |
Never say containers “don’t have an OS” — correct answer is:
They include only minimal system libraries, not a full OS.
Answer:
The Docker lifecycle includes:
Write Dockerfile
Build image → docker build
Run container → docker run
Tag & Push image to registry (Docker Hub, ECR, GCR)
Pull image on any environment
Manage containers (start/stop/remove/prune)
Answer:
Docker Client (CLI) – sends commands
Docker Daemon – core engine that executes actions
Docker Images – read-only templates
Docker Containers – running instances of images
Docker Registry – stores images (Docker Hub, ECR, private registry)
Daemon is the “heart” of Docker — if it stops, Docker actions cannot be executed.
COPY and ADD in Dockerfile?Answer:
COPY – Copies files/folders from local machine → image (preferred)
ADD – Same as COPY + supports downloading from URL or auto-extracting archives.
Use COPY unless you specifically need ADD’s special features.
CMD and ENTRYPOINT?Answer:
| CMD | ENTRYPOINT |
| Provides default arguments | Provides main executable |
| Can be overridden using CLI | Not overridden by default |
docker run image ls → ls replaces CMD | docker run image ls → ls becomes argument |
Best practice: Use ENTRYPOINT for the main command and CMD for default arguments.
Example:
ENTRYPOINT ["python", "app.py"]
CMD ["--port", "8000"]
Answer:
bridge – default network for containers
host – container shares host network
overlay – used in multi-host (Swarm/Kubernetes)
macvlan – container appears as a physical device on network
none – no network
Answer:
Create a custom bridge network:
docker network create secure_net
docker run --network secure_net ...
Containers on different networks cannot talk to each other unless explicitly connected.
Answer:
It allows you to use multiple FROM statements and copy only the required build artifacts into the final image.
Why?
Reduces image size
Removes build tools from production image
Improves security
Example: Reduce image from ~800MB → 1MB using scratch/alpine.
Answer:
Distroless images (e.g., gcr.io/distroless/...) are minimal images that contain only:
your application
required runtime dependencies
They do not contain:
❌ shell (sh, bash)
❌ package managers (apt, yum)
❌ OS utilities (ping, curl)
Benefit:
Extremely secure, tiny, no attack surface.
Docker daemon is one single process
If daemon crashes → containers may stop or fail
Modern solution: Podman (daemonless, rootless).
By default, daemon runs with root privileges
If a container is compromised, host becomes vulnerable
Solution:
Use rootless Docker
Use Podman (runs fully rootless)
Always set USER in Dockerfile
Developers often install unnecessary tools
Leads to huge (GB-sized) images
Slow deploys, security risks
Solutions:
Multi-stage builds
Distroless images
Base images like alpine
Wrong port mappings
Misuse of host network
Containers unintentionally communicating
Solution:
Custom networks & proper isolation.
Using outdated base images
Running containers as root
Storing secrets inside images
Solution:
Scan images (Trivy, Anchore)
Use secrets manager
Use non-root user in Dockerfile