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
# 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 downCommon kubectl commands
# 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-namespaceDockerfile 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
# 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
1. Which kubectl flag shows logs from the last crashed instance of a Pod that is currently restarting?
2. What is the effect of the Dockerfile EXPOSE instruction?
3. What kubectl shortname refers to persistentvolumeclaims?
4. What is the relationship between ENTRYPOINT and CMD in a Dockerfile?
5. Which command reverts a Deployment to its previous revision after a bad rollout?
Was this page helpful?
You May Also Like
kubectl Basics
A practical introduction to kubectl, the command-line tool used to interact with a Kubernetes cluster's API server.
Writing a Dockerfile
A practical guide to Dockerfile syntax and the core instructions used to build a custom image from scratch.
Docker & Kubernetes Interview Questions
A curated set of frequently asked Docker and Kubernetes interview questions with thorough answers spanning images, networking, pods, and scaling.
Common Docker & Kubernetes Pitfalls
The recurring mistakes engineers make with Docker and Kubernetes in production, why they happen, and how to avoid or fix each one.
Related Reading
Related Study Notes in DevOps
Browse all study notesNginx Study Notes
DevOps · 30 topics
DevOpsAnsible Study Notes
DevOps · 30 topics
DevOpsAdvanced Kubernetes Study Notes
Kubernetes · 30 topics
DevOpsAdvanced Bash Scripting Study Notes
Bash · 30 topics
DevOpsApache Kafka Study Notes
Kafka · 30 topics
DevOpsCI/CD Tools & Pipelines Study Notes
YAML · 37 topics