100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
YAML

Docker & Kubernetes Quick Reference

A cheat-sheet of essential Docker CLI commands, kubectl commands, Dockerfile instructions, and kubectl resource shortnames for fast lookup.

Interview PrepIntermediate9 min readJul 8, 2026
Analogies

A Fast-Lookup Cheat Sheet

This topic is a condensed reference rather than a narrative — use it to quickly recall exact command syntax, Dockerfile instructions, and kubectl shortnames during study or before an interview. Every command shown is valid as written and reflects common day-to-day usage rather than exhaustive flag lists.

🏏

Cricket analogy: This topic is like a pocket-sized fielding-position cheat sheet a captain glances at before setting the field, not a full coaching textbook, listing exact terminology so you can recall it instantly during a live match or interview.

Common Docker CLI commands

bash
# Build an image from a Dockerfile in the current directory
docker build -t myapp:1.0 .

# Run a container, mapping host port 8080 to container port 80
docker run -d -p 8080:80 --name web myapp:1.0

# List running containers
docker ps

# List all containers, including stopped ones
docker ps -a

# View logs from a container (follow mode)
docker logs -f web

# Open a shell inside a running container
docker exec -it web sh

# Stop and then remove a container
docker stop web
docker rm web

# List local images
docker images

# Remove an image
docker rmi myapp:1.0

# Create and use a named volume
docker volume create app-data
docker run -d -v app-data:/var/lib/data myapp:1.0

# Show resource usage of running containers
docker stats

# Start services defined in docker-compose.yml
docker compose up -d

# Stop and remove docker compose services
docker compose down

Common kubectl commands

bash
# List Pods in the current namespace
kubectl get pods

# List Pods across all namespaces
kubectl get pods --all-namespaces

# Show detailed info and recent events for a Pod
kubectl describe pod my-pod

# Stream logs from a Pod (add --previous for the last crashed instance)
kubectl logs -f my-pod

# Open a shell inside a running Pod's container
kubectl exec -it my-pod -- sh

# Apply a manifest file to create/update resources
kubectl apply -f deployment.yaml

# Delete resources defined in a manifest file
kubectl delete -f deployment.yaml

# Scale a Deployment to 5 replicas
kubectl scale deployment my-app --replicas=5

# Check rollout status of a Deployment
kubectl rollout status deployment/my-app

# Roll back a Deployment to the previous revision
kubectl rollout undo deployment/my-app

# Forward a local port to a Pod for local debugging
kubectl port-forward pod/my-pod 8080:80

# View current context and switch namespaces
kubectl config current-context
kubectl config set-context --current --namespace=my-namespace

Dockerfile instruction reference

  • FROM — sets the base image for the build stage
  • RUN — executes a command and commits the result as a new layer
  • COPY — copies files/directories from the build context into the image
  • ADD — like COPY, but can also extract local archives and fetch URLs
  • WORKDIR — sets the working directory for subsequent instructions
  • ENV — sets an environment variable available at build and run time
  • ARG — defines a build-time-only variable passed via --build-arg
  • EXPOSE — documents which port(s) the container listens on (does not publish them)
  • USER — sets the user (and optionally group) that subsequent instructions and the container process run as
  • ENTRYPOINT — defines the fixed executable that always runs when the container starts
  • CMD — provides default arguments to ENTRYPOINT, or the command if no ENTRYPOINT is set
  • HEALTHCHECK — defines a command Docker runs periodically to determine container health

Common kubectl resource shortnames

  • po — pods
  • deploy — deployments
  • rs — replicasets
  • svc — services
  • ns — namespaces
  • cm — configmaps
  • sa — serviceaccounts
  • pv — persistentvolumes
  • pvc — persistentvolumeclaims
  • ing — ingresses
  • hpa — horizontalpodautoscalers
  • sts — statefulsets
  • ds — daemonsets
  • no — nodes

Example: quick label and describe workflow

bash
# Get pods with a shortname, showing labels
kubectl get po -l app=web --show-labels

# Describe a service by shortname
kubectl describe svc web

# Get all deployments and replicasets in one call
kubectl get deploy,rs -n my-namespace

# Watch pods update in real time
kubectl get po -w
  • docker build/run/ps/logs/exec cover the vast majority of day-to-day Docker CLI use
  • kubectl get/describe/logs/apply/rollout are the core verbs for everyday cluster operations
  • ENTRYPOINT defines the fixed command; CMD supplies default (overridable) arguments to it
  • EXPOSE is documentation only — it does not publish a port; -p/--publish does that at runtime
  • Resource shortnames (po, deploy, svc, ns, pvc, hpa) save typing and are worth memorizing
  • kubectl get resource,resource combines multiple resource types in a single query

Practice what you learned

Was this page helpful?

Topics covered

#YAML#DockerKubernetesStudyNotes#DevOps#DockerKubernetesQuickReference#Docker#Kubernetes#Quick#Reference#StudyNotes#SkillVeris