Developer and Text Tools

Docker and kubectl Commands You Need When Something Breaks

The Docker, Compose and kubectl commands for daily work and troubleshooting: logs, shells, failing pods, rollbacks, disk clean-up and what each flag does.

Saizul Amin
Saizul Amin30 Oct 2026 · 3 min read
Docker and kubectl Commands You Need When Something Breaks

Docker and kubectl Commands You Need When Something Breaks

Containers make deployments repeatable, but when something goes wrong you need the right command quickly, and docker and kubectl each have dozens of subcommands with similar names. The free Docker and Kubernetes CLI Reference lists the commands by task with their flags explained and the destructive ones flagged. This guide walks through the situations where you need them most.

A container will not start

  1. docker ps -a shows all containers, including ones that exited, with their status and exit code.
  2. docker logs name shows what the container printed before it died; add -f to follow and --tail 100 to limit the output.
  3. docker inspect name shows the full configuration: environment, mounts, networks and the command that was run.
  4. To look around inside the image, start a throwaway shell: docker run --rm -it image sh.

Exit code 137 usually means the container was killed for using too much memory; check the memory limit.

Getting inside a running container

docker exec -it name sh opens a shell in a running container. Many minimal images have no bash, so try sh. For Compose services, docker compose exec service sh does the same using the service name.

Compose day to day

  • docker compose up -d starts everything in the background.
  • docker compose up -d --build rebuilds images first.
  • docker compose logs -f service follows one service.
  • docker compose config prints the final merged file, the quickest way to catch an indentation or variable problem.
  • docker compose down stops and removes the services; adding -v also deletes volumes and their data, so it is flagged.

A Kubernetes pod is failing

Work from the outside in:

  1. kubectl get pods shows the status. CrashLoopBackOff means the container keeps exiting; ImagePullBackOff means the image name, tag or registry credentials are wrong; Pending usually means no node has enough resources.
  2. kubectl describe pod name lists events, including probe failures and scheduling problems.
  3. kubectl logs name --previous shows the output of the crashed container, not the new one that is starting.
  4. kubectl get events --sort-by=.lastTimestamp shows what happened recently across the namespace.
  5. kubectl debug attaches a container with tools to a running pod whose image has none.

Rolling back

kubectl rollout undo deploy/name returns to the previous version immediately. kubectl rollout status waits and tells you whether a rollout completed, and kubectl rollout restart replaces all pods, which is useful after changing a ConfigMap.

Reaching a service from your laptop

kubectl port-forward svc/name 8080:80 makes a cluster service available on localhost:8080 without exposing it publicly.

Freeing disk space without losing data

docker system df shows how much space images, containers and volumes use. docker system prune removes stopped containers, unused networks and dangling images, and keeps volumes. docker system prune -a --volumes removes everything unused, including volumes and the data in them, so check what those volumes hold first.

Building and publishing images

docker build -t name:tag . builds from the Dockerfile in the current folder, and --no-cache --pull forces a clean rebuild with the newest base image. Tag releases with a version or commit hash rather than latest, so every deployment points at a known image and a rollback picks the right one. docker buildx build --platform linux/amd64,linux/arm64 builds for Intel and ARM servers in one go.

Search in plain words, such as logs, shell, rollback or disk, or pick a section. Tick "only commands that need care" to see the destructive ones. Replace names in angle brackets, and download the list as CSV to keep in your team's runbook.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages