Kritim Yantra
Apr 12, 2025
If you're preparing for a mid-level or advanced Docker interview in 2025, this blog covers complex concepts, best practices, and real-world scenarios. These questions will test your deep understanding of Docker architecture, security, orchestration, and optimization.
Answer:
Docker follows a client-server architecture:
dockerd
) → Background service managing containers, images, networks, and storage. docker
CLI) → Command-line tool to interact with the daemon. Flow:
docker run
→ CLI sends request to dockerd
. Answer:
Namespaces → Isolate processes (each container has its own view of OS resources).
PID
(Process IDs) NET
(Networking) MNT
(Filesystem mounts) UTS
(Hostname isolation) IPC
(Inter-process communication) User
(User permissions)Control Groups (cgroups) → Limit resource usage (CPU, memory, disk I/O).
Example:
docker run --cpu-shares=512 --memory=1g nginx
Answer:
Driver | Description | Use Case |
---|---|---|
bridge (Default) |
Private internal network (NAT) | Single-host container communication |
host |
Shares host’s network stack | High-performance apps (bypasses isolation) |
overlay |
Multi-host networking (Swarm/K8s) | Distributed apps across hosts |
macvlan |
Assigns MAC addresses to containers | Legacy apps needing MAC spoofing |
none |
No networking | Isolated testing |
Example:
docker network create --driver=overlay my_overlay_net
Answer:
Example (Swarm):
docker service create --network=my_overlay_net --name web nginx
Answer:
Type | Storage Location | Persistence | Use Case |
---|---|---|---|
Volumes | Managed by Docker (/var/lib/docker/volumes ) |
Yes | Databases, shared data |
Bind Mounts | Host filesystem (any path) | Yes | Development (live code reload) |
tmpfs | Host RAM only | No (ephemeral) | Temporary secrets, sensitive data |
Example:
docker run -v /host/path:/container/path nginx # Bind mount
docker run --tmpfs /app/cache nginx # tmpfs
Answer:
docker run --rm -v my_volume:/data -v $(pwd):/backup busybox tar cvf /backup/backup.tar /data
docker run --rm -v my_volume:/data -v $(pwd):/backup busybox tar xvf /backup/backup.tar -C /
Answer:
USER 1000
docker run --cap-drop=ALL --cap-add=NET_BIND_SERVICE nginx
docker run --read-only nginx
docker scan nginx
echo "password" | docker secret create db_pass -
Answer:
Docker Bench for Security is a script that audits containers against CIS benchmarks:
Usage:
docker run -it --net host --pid host --userns host --cap-add audit_control \
-v /var/lib:/var/lib \
-v /var/run/docker.sock:/var/run/docker.sock \
docker/docker-bench-security
Answer:
Feature | Docker Swarm | Kubernetes |
---|---|---|
Complexity | Simple | Complex |
Scaling | Fast | Slower (but more granular) |
Networking | Overlay (built-in) | CNI plugins (flexible) |
Use Case | Small to medium clusters | Large-scale deployments |
Swarm Example:
docker swarm init
docker service create --replicas 3 --name web nginx
Answer:
docker service ps --no-trunc my_service
docker service update --rollback my_service
Answer:
FROM node:14 as builder
COPY . .
RUN npm build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
alpine
, slim
). RUN apt-get update && apt-get install -y \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
Answer:
docker stats
docker top
: docker top my_container
perf
or htop
: docker exec -it my_container htop
Answer:
- name: Build and Push
run: |
docker build -t myapp:$GITHUB_SHA .
docker push myapp:$GITHUB_SHA
kubectl set image deployment/myapp myapp=myapp:$GITHUB_SHA
Answer:
echo "db_password" | docker secret create db_pass -
docker service create --name db --secret db_pass mysql
cat /run/secrets/db_pass
These advanced Docker questions cover architecture, security, orchestration, and optimization. Mastering these concepts will prepare you for senior DevOps or cloud engineering roles in 2025.
Need more depth on a topic? Ask in the comments! 🚀
Bonus: For hands-on practice, try:
Happy learning! 🐳
No comments yet. Be the first to comment!
Please log in to post a comment:
Continue with Google