Docker and Kubernetes solve different problems in containerized systems: Docker builds and runs individual containers, while Kubernetes orchestrates many containers across a cluster of machines.
Key Points: • Docker packages an application with its dependencies into a portable image and provides the runtime to build and run containers from that image. • Kubernetes takes a set of containers, described declaratively, and schedules them across a cluster of nodes, keeping the desired number of replicas running. • Kubernetes automates load balancing, service discovery, rolling updates, and self-healing by restarting or rescheduling failed containers. • Docker operates at the level of a single container on a single host; Kubernetes operates at the level of a fleet of containers across many hosts. • Kubernetes can run containers built by Docker or other container runtimes, since it consumes standard OCI images rather than requiring Docker specifically.
Example: A developer uses docker build and docker run to package and test a Spring Boot service locally, then deploys that same image to a Kubernetes cluster, which keeps three replicas running, restarts any that crash, and load-balances traffic between them.
Interview Tip: A concise interview answer is:
"Docker builds and runs a single container from an image, while Kubernetes orchestrates many containers across a cluster, handling scaling, load balancing, service discovery, and self-healing. They're complementary: Docker produces the image, and Kubernetes runs and manages it at scale."