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.

Storage & networking

Publish a host port deliberately

Docker & Kubernetes

-p maps a host endpoint to a container port. Binding 127.0.0.1 restricts the published host endpoint to loopback.

Fragment

Docker & Kubernetes · Publish a host port deliberately
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker run --rm -p 127.0.0.1:8080:8080 demo:local

The app inside the container usually must bind an interface reachable from the container network, rather than its own loopback only.

Bind mount versus named volume

Docker & Kubernetes

A bind mount exposes a host path. A named volume is managed by Docker. A mount can hide image files at the mounted target.

Fragment

Docker & Kubernetes · Bind mount versus named volume
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker run --rm \
  --mount type=bind,src="$PWD/input",dst=/input,readonly \
  demo:local

docker run --rm \
  --mount type=volume,src=demo-data,dst=/data \
  demo:local

Durable storage is not a backup. Host path ownership and permissions still apply.

Connect containers by network identity

Docker & Kubernetes

A user-defined bridge network supplies container-name resolution between attached containers. localhost inside a container means that container’s own network namespace.

Fragment

Docker & Kubernetes · Connect containers by network identity
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker network create demo-net
docker run --rm --network demo-net --name api demo:local

Use the service/container name and container port for peers on that network; a published host port serves a different route.

Inspect volume ownership before cleanup

Docker & Kubernetes

Volumes can outlive containers. Inspect their names, mountpoints and consumers before deciding that a particular volume is disposable.

Fragment

Docker & Kubernetes · Inspect volume ownership before cleanup
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
docker volume ls
docker volume inspect demo-data
docker container ls -a --filter volume=demo-data

A volume can hold the only copy of application data; container removal and volume deletion have different consequences.