Beginner Level
This section covers fundamental concepts of Docker and Kubernetes, including basic principles, commands, and common practices.
Docker Basics
What is Docker, and why is it used?
Docker is a containerization platform: it packages an application together with its runtime, dependencies, and configuration into a single portable unit — the container — that runs identically on any machine.
Why it became the standard for DevOps:
- "Works on my machine" dies — the image is the environment; dev, CI, and prod run the same bits
- Lightweight and fast — containers share the host kernel and start in seconds (vs minutes for VMs)
- The deployable artifact — the image is versioned, immutable, and what your CI/CD pipeline actually ships
- Foundation of orchestration — Kubernetes schedules Docker (and OCI) containers
What is the difference between Docker and a virtual machine?
The practical takeaway: VMs give you stronger isolation and any OS you like; containers give you speed, density, and reproducibility — which is why clouds run VMs underneath and containers on top, and why security-sensitive multi-tenant workloads may still demand VM-level boundaries.
What is a Docker image, and what is a container?
- Image — a read-only, immutable template built from a Dockerfile: application code, runtime, dependencies, and default command, stored as layered filesystem snapshots
- Container — a running instance of an image: Docker adds a thin writable layer on top of the image layers and isolates the process
The analogy that lands: image is to class as container is to object. One image can spawn many containers; containers never modify the image — that's why a rebuilt container from the same image behaves identically, and why images (not running servers) are what CI/CD stores and deploys.
How do you create and run a Docker container?
bash-d— detached mode (runs in the background)--name myapp— a readable name instead of a random ID-p 8080:80— map host port 8080 to the container's port 80nginx— the image to run (pulled from a registry if not present locally)
Follow-ups worth knowing:
docker logs myappto see output,docker stop myapp/docker rm myappto tear down, anddocker psto list what's running.What is the purpose of the Dockerfile?
A Dockerfile is the build recipe for an image — every instruction creates a filesystem layer:
dockerfileBuild it with
docker build -t myapp:1.0 .. The instruction set to know:FROM,COPY/ADD,RUN(build-time execution),CMD/ENTRYPOINT(runtime command),ENV,EXPOSE, andUSER. Because instructions are ordered layers, their order is a performance decision (see layer caching).What are Docker volumes, and when do you use each type?
Containers are ephemeral — data written inside them is lost when the container is removed. Volumes persist data outside that lifecycle:
bash- Named volumes — the default choice for persistence (databases); Docker manages location and lifecycle, portable across hosts
- Bind mounts — map a specific host directory; ideal for local development (live code editing) — and dangerous in production (host coupling, permission drift)
- tmpfs — in-memory, for secrets or scratch data that must never hit disk
What is Docker Compose?
Compose defines and runs multi-container applications from one declarative file — the local-development standard:
yamlOne command starts the whole stack:
docker compose up -d(thedown/logs/psverbs manage it). Compose creates a shared network so services reach each other by service name (db:5432). Its boundaries to know: it's for single-host development and testing — production orchestration is Kubernetes, not Compose.What is the difference between CMD and ENTRYPOINT in a Dockerfile?
Both define what runs when the container starts — the distinction is what can be overridden:
dockerfiledocker run myapprunsnginx -g "daemon off;" -p 80docker run myapp -p 8080runsnginx -g "daemon off;" -p 8080— the run arguments replace CMD, not ENTRYPOINTdocker run --entrypoint sh myappis the escape hatch to override the entrypoint (handy for debugging)
Pattern to remember: ENTRYPOINT for the fixed program, CMD for its default arguments.
How do you inspect and debug a Docker container?
bashTwo debugging facts worth knowing: a container that exits immediately usually has a crashing entrypoint —
docker logsshows the error anddocker ps -ashows its exit code; and if the image is minimal (no shell),docker execfails — usedocker execagainst a debug sidecar or a-debugimage variant.What are Docker image layers?
Every Dockerfile instruction produces a read-only filesystem layer; layers stack, and containers add one writable layer on top:
codeWhy layers matter:
- Caching — unchanged layers are reused on rebuild; that's why you copy dependency manifests before source code (see layer-caching questions)
- Sharing — images built on the same base share those layers on disk and in registries
- Cleanup gotcha — deleting a file in a later layer doesn't shrink the image; the file still lives in the earlier layer (so never
COPY . .thenRUN rm secrets— use.dockerignoreand multi-stage builds)
How do you clean up unused Docker resources?
bashpruneis a CI-runner housekeeping staple (builders fill disks with cached layers). The caution to show:-aand--volumesare destructive to anything not currently in use — on shared hosts, verify what's running first, and treat volume deletion as a data-deletion decision, not cleanup.What is a container registry?
A registry stores and distributes versioned images — the pipeline's artifact store:
- Public — Docker Hub; private/managed — ECR, GCR/Artifact Registry, GHCR, Harbor (self-hosted)
- Push/pull model — CI builds and pushes
myapp:1.4.2; any host or cluster pulls exactly that tag
Registry practices that matter in interviews: tag immutability discipline (never reuse tags; avoid
latestin deployments — you can't roll back to "latest"), private registries for proprietary code, and registries as the natural scanning point (Trivy/Snyk check images on push).
Kubernetes Basics
What is Kubernetes, and what problem does it solve?
Kubernetes (K8s) is a container orchestration platform: it runs your containers across a fleet of machines and keeps the desired state alive without human babysitting.
The problems it takes over (each one a thing you'd otherwise script yourself):
- Self-healing — a crashed or dead-node container is rescheduled automatically
- Scaling — horizontal scaling of replicas, cluster autoscaling
- Rolling updates & rollback — new versions replace old with health gates
- Service discovery & load balancing — stable networking to moving pods
- Secret/config management — injected into containers declaratively
The framing to give: Docker runs containers on one host; Kubernetes runs them on a data center, declaratively.
What is the architecture of a Kubernetes cluster?
Two planes:
- Control plane (the brain) — API server (the entry point for everything), etcd (the cluster's state store), scheduler (assigns pods to nodes), controller manager (reconciles desired vs actual state)
- Worker nodes (the muscle) — kubelet (agent that runs pods on the node), kube-proxy (network rules for services), and the container runtime (containerd)
Key mental model: everything talks to the API server, and every component works by reconciling — reading desired state from the API and making reality match. You never address nodes directly; you declare state to the API server.
What is a Pod?
The Pod is Kubernetes' smallest deployable unit — one or more containers that share a network namespace (same IP, can talk over
localhost), storage volumes, and lifecycle.Why pods exist instead of running containers directly: the shared "pod sandbox" lets tightly coupled helpers (a log shipper, an auth proxy) live beside the main container — the sidecar pattern. In practice, most pods hold exactly one container, and you rarely create pods directly: controllers (Deployments) own them.
What is a Deployment, and why not create Pods directly?
A Deployment is a controller that manages a set of identical pods — it's the standard way to run stateless work:
yamlThe controller continuously reconciles: a pod dies → a new one appears; the image is changed → a rolling update replaces pods with health gates; you want yesterday's version →
kubectl rollout undo. Pods directly have none of that — which is why "never create naked pods" is the beginner rule.What is a Kubernetes Service, and what are its types?
Pods are ephemeral — they die, reschedule, and change IPs. A Service gives them a stable virtual IP (and DNS name) that routes to the current healthy pods, selected by labels:
- ClusterIP (default) — internal-only address; service-to-service traffic inside the cluster
- NodePort — opens a static port (30000–32767) on every node for external access — quick demos, not production
- LoadBalancer — provisions a cloud load balancer pointing at the service; the standard external entry on managed clouds
- ExternalName / Headless — special cases: DNS alias to an external service; no VIP (DNS returns pod IPs directly — used by stateful sets)
The selection mechanism to mention: Services use label selectors, and endpoints update automatically as pods come and go — that's how a moving set of pods keeps a stable address.
What is a Namespace, and when do you use one?
A namespace is a virtual cluster inside the cluster: resources get scoped into named groups (
kubectl get pods -n payments).- Purpose — team/project isolation, environment separation (dev/staging clusters often use namespaces), and resource quotas per namespace
- What it is NOT — a security boundary by itself (network policies and RBAC provide that), and certain resources (nodes, PVs, the API itself) are cluster-scoped, outside all namespaces
Conventions:
default,kube-system(control-plane components — hands off),kube-public. The common pattern is namespace-per-team or namespace-per-environment on shared clusters, paired with quotas and RBAC.What is kubectl, and which commands do you use daily?
kubectlis the CLI client for the Kubernetes API — how humans (and pipelines) read and change cluster state:bashThe habit to demonstrate: when something breaks, the order is
get(does it exist?) →describe(what do the events say?) →logs(what is it saying?) →exec(look inside).describeshowing the Events section answers most beginner-level cluster questions.What is the difference between
kubectl applyandkubectl create?kubectl create -f file.yaml— imperative: creates the resource once; errors if it already exists. Nothing is remembered about the filekubectl apply -f file.yaml— declarative: creates or updates to match the file, storing the last-applied configuration to compute diffs. Re-runnable, idempotent
This distinction is the gateway to GitOps:
apply(driven from versioned manifests, by a person or by Argo CD/Flux) is how cluster state should be changed; imperativecreate/editproduce untracked snowflakes that drift from the repo. In interviews, answering "apply, from Git" signals you've operated a real cluster.What are labels and selectors in Kubernetes?
Labels are key-value tags attached to every Kubernetes object; selectors query objects by those labels — the connective tissue of the whole API:
yamlbashEverything depends on them: Services find pods via selectors, Deployments track their pods, network policies target groups of pods, and
kubectlfiltering uses them. The recommended convention: label every resource with app/version/team — because selectors are how tools (and your rollouts) find their targets, inconsistent labels break deployments in confusing ways.How does Kubernetes handle container failures (self-healing)?
Self-healing is the reconciliation loop: the declared state (3 replicas, this image) is continuously compared to reality, and differences are corrected:
- Container crashes — the kubelet restarts it according to the restartPolicy (Always is the Deployment default, with exponential backoff)
- Node dies — the node's lease expires, the controller manager marks its pods as gone, and the scheduler recreates them on healthy nodes
- Unhealthy-but-running container — this is what probes catch: if a liveness probe fails, the kubelet restarts the container; if a readiness probe fails, the pod is removed from Service endpoints (see intermediate questions for probe types)
The important boundary: Kubernetes heals containers and pods — it cannot fix an application that is broken-but-alive unless you define a probe that detects that state. Self-healing is only as good as your health definitions.
Contribute & Stay Updated
Want to contribute? We welcome contributions! If you have insights, new tools, or improvements, feel free to submit a pull request.
How to Contribute?
- Read the CONTRIBUTING.md guide.
- Fix errors, add missing topics, or suggest improvements.
- Submit a pull request with your updates.
Community & Support
GitHub: @NotHarshhaa Blog: ProDevOpsGuy Telegram Community: Join Here