Reference

Docker & Kubernetes

Read image builds, container commands, Compose files and Kubernetes workload configuration.

Scope and conventions

Docker CLI/Dockerfile, Docker Compose and Kubernetes native YAML/kubectl. These are complementary tools, not interchangeable editions. Commands assume your own disposable local environment; image names, cluster objects and paths are illustrative. Nothing runs from this guide.

Container runtime

Start a container with an explicit identity

Docker & Kubernetes

--name names the container; -d detaches the client; --rm removes the container after it exits.

Fragment

Docker & Kubernetes · Start a container with an explicit identity
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker run --name demo --rm -d demo:local

--rm deletes the container writable layer on exit; it does not make external side effects reversible.

Inspect logs and process state

Docker & Kubernetes

logs reads captured stdout/stderr. inspect shows container configuration and runtime state. A running process is not necessarily a healthy application.

Fragment

Docker & Kubernetes · Inspect logs and process state
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker logs --tail 50 demo
docker logs -f demo
docker inspect demo
docker top demo

Run an additional process in a container

Docker & Kubernetes

exec starts a process in an already-running container. -i keeps stdin open; -t allocates a terminal.

Fragment

Docker & Kubernetes · Run an additional process in a container
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker exec -it demo sh

This requires a shell in the image. Minimal/scratch images may have no shell or debug tools.

Stop with a graceful termination window

Docker & Kubernetes

docker stop sends the configured stop signal, normally SIGTERM, then uses SIGKILL after the grace timeout if needed.

Fragment

Docker & Kubernetes · Stop with a graceful termination window
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker stop --timeout 10 demo

The main process must receive/handle signals and stop its children appropriately.

Distinguish removal and pruning scope

Docker & Kubernetes

Removing a container deletes its writable layer. Removing an image deletes a local image reference/content when permitted. Broad prune commands have wider scope.

Fragment

Docker & Kubernetes · Distinguish removal and pruning scope
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker container ls -a
docker image ls
# Inspect exact IDs before any removal.

Volumes and other resources have their own lifecycle. Avoid treating prune as routine troubleshooting.

Start an existing container versus creating another

Docker & Kubernetes

run creates a new container from an image. start restarts an existing stopped container with its retained configuration and writable layer.

Fragment

Docker & Kubernetes · Start an existing container versus creating another
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker container ls -a
docker start demo
docker logs --tail 30 demo

A container launched with --rm may already have been removed after exit. Rebuilding its image does not update an existing container.

Set runtime environment and resource limits

Docker & Kubernetes

-e supplies an environment variable; --env-file loads environment entries from a file. --cpus limits CPU allocation; --memory sets a memory limit.

Fragment

Docker & Kubernetes · Set runtime environment and resource limits
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker run --rm -e APP_MODE=preview \
  --cpus=1 --memory=256m demo:local

Choose limits based on the application and host. A runtime environment is visible through process/container inspection; do not treat it as a universal secret store.

Remove exact stopped containers or image references

Docker & Kubernetes

container rm removes the named stopped container. image rm removes a local image reference/content when permitted. Named volumes have a separate removal lifecycle.

Fragment

Docker & Kubernetes · Remove exact stopped containers or image references
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker inspect demo
docker container rm demo
docker image rm demo:local

These commands mutate local state. Inspect the exact name/ID first; -f changes container-removal behavior by allowing forced removal of running containers.