Docker Interview Q&A

1. What is Docker?

Docker is a platform for building, running, and managing applications inside containers. It ensures portability, isolation, and lightweight deployment compared to VMs.

2. How are containers different from Virtual Machines?

Containers share the host OS kernel, start in seconds, and are lightweight. VMs have their own OS, take minutes to boot, and are heavier.

3. What is Docker Lifecycle?

Image creation → Container run → Container stop → Container remove. Typical commands: docker build, docker run, docker stop, docker rm.

4. What are the main components of Docker?

Docker Client, Docker Daemon, Docker Images, Docker Containers, Docker Registry.

5. What is the difference between COPY and ADD in Dockerfile?

COPY only copies files from local system into the image. ADD can also extract tar archives and fetch files from remote URLs.

6. What is the difference between CMD and ENTRYPOINT in Dockerfile?

CMD provides a default command that can be overridden. ENTRYPOINT defines a fixed command; user arguments are appended.

7. What are the networking types in Docker? What is default?

Bridge (default), Host, None, and Overlay. The default networking type is Bridge.

8. How to isolate networking between containers?

Use custom bridge networks, firewall rules, or user-defined networks with separate subnets to isolate communication.

9. What is a Multi-stage build in Docker?

It allows creating smaller images by using multiple FROM statements. Build dependencies are in one stage, and only required files are copied to the final image.

10. What are Distroless Images in Docker?

Distroless images contain only the application and its runtime libraries without OS or package managers, reducing vulnerabilities and image size.

11. What real-time challenges have you faced with Docker?

Single daemon process creates SPOF, Docker Daemon running as root is a security risk, and too many containers on one host can cause resource constraints.

12. What steps would you take to secure containers?

Use minimal or distroless images, configure networking properly, scan images with security tools, run as non-root, and apply resource limits.

13. What is Docker Daemon?

Docker Daemon (dockerd) is a background process that manages images, containers, volumes, and networks. It listens to client commands and interacts with registries.

14. What is Docker Registry?

A Docker Registry stores images. Docker Hub is the default public registry, but private registries (AWS ECR, Nexus, Artifactory) are also used.

15. What is Docker Compose?

Docker Compose is a tool for defining and running multi-container applications using a YAML file to configure services, networks, and volumes.

16. How do you persist data in Docker?

Use Volumes (preferred) or Bind Mounts. Volumes are managed by Docker and survive container restarts.

17. How do you optimize Docker Images?

Use smaller base images like Alpine, multi-stage builds, combine RUN statements, and clean up package caches.

18. How do you monitor Docker containers?

Using commands like docker stats, docker logs, and external tools like Prometheus, Grafana, or cAdvisor.

19. What is the difference between Docker Swarm and Kubernetes?

Docker Swarm is Docker's native clustering and orchestration tool. Kubernetes is a more advanced, widely adopted container orchestration system with richer features.

20. What happens when you run docker run?

The client sends request to daemon, image is checked locally, pulled from registry if not available, then a container is created and started.