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.

Configuration & resources

Select context and namespace

Docker & Kubernetes

A context selects cluster, credentials and a default namespace. -n overrides the namespace for one command.

Fragment

Docker & Kubernetes · Select context and namespace
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
kubectl config current-context
kubectl config get-contexts
kubectl get pods -n demo

Check the target before mutations. Namespaces are administrative scope, not complete network/security isolation.

Load configuration through explicit keys

Docker & Kubernetes

ConfigMap stores non-secret configuration. A Pod can reference a specific key as an environment variable.

Fragment

Docker & Kubernetes · Load configuration through explicit keys
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
# Fragment under a container:
env:
  - name: APP_MODE
    valueFrom:
      configMapKeyRef:
        name: app-config
        key: mode

Existing process environment variables do not update automatically when the ConfigMap changes.

Recognize a Secret reference

Docker & Kubernetes

Secret objects carry sensitive values for workloads. Base64 in Secret.data is encoding, not encryption.

Fragment

Docker & Kubernetes · Recognize a Secret reference
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
# Fragment under a container:
env:
  - name: API_TOKEN
    valueFrom:
      secretKeyRef:
        name: app-credentials
        key: token

Apply least-privilege access, appropriate encryption at rest and careful handling of logs/manifests.

Read requests and limits with units

Docker & Kubernetes

Requests contribute to scheduling and resource allocation. Limits constrain use. CPU m means millicores; Mi/Gi are binary memory units.

Fragment

Docker & Kubernetes · Read requests and limits with units
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
resources:
  requests:
    cpu: "250m"
    memory: "128Mi"
  limits:
    cpu: "500m"
    memory: "256Mi"

CPU limiting and memory-limit enforcement differ; memory exhaustion can cause an OOM kill. Requests are not a health check.

Attach persistent storage

Docker & Kubernetes

A PersistentVolumeClaim requests storage through the cluster’s storage system. A volumeMount connects that volume to a container path.

Fragment

Docker & Kubernetes · Attach persistent storage
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
# Pod-spec fragments:
volumes:
  - name: data
    persistentVolumeClaim:
      claimName: demo-data
# Under a container:
volumeMounts:
  - name: data
    mountPath: /data

The claim must exist or be provisioned. Access modes and reclaim policy affect ownership/lifecycle; persistence is not backup.

Read a container security context

Docker & Kubernetes

Security context declares execution constraints. These settings require an application/image compatible with them.

Fragment

Docker & Kubernetes · Read a container security context
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
securityContext:
  runAsNonRoot: true
  allowPrivilegeEscalation: false
  readOnlyRootFilesystem: true
  capabilities:
    drop: ["ALL"]

A read-only root filesystem needs separate writable mounts for required temporary/output paths.