Container Runtime Operations
A practical guide to container lifecycles, configuration, resource controls, logging, and evidence-based troubleshooting with Docker and Kubernetes.
Container Lifecycles and Workload Management
Starting and controlling a container
A container is an isolated process created from an image. Docker’s docker run command creates and starts a new container. By default, it runs in the foreground; add -d to run it in the background. In either case, the container stays running only while its main process is running. When that process exits, the container stops.
The source’s example demonstrates the basic lifecycle:
docker run --name web -d -p 8080:80 nginx:alpine
docker ps
docker stop web
docker start web
docker rm web
Here, --name web assigns a readable identifier, and -p 8080:80 maps port 8080 on the host to port 80 inside the container. docker ps lists running containers. docker stop web stops the container, while docker start web starts that stopped container again with its existing configuration. docker rm web removes the container.
Removing a container is not the same as removing separately managed data: data stored in a volume can persist after the container is removed. A restart policy such as --restart unless-stopped can request automatic restarts after a container exits, but restarting a process does not resolve the underlying cause of a failure.
Managing workloads with Kubernetes
In an orchestrated environment, operators usually manage workloads rather than manually starting individual containers. Kubernetes runs containers inside Pods and tracks states such as Waiting, Running, and Terminated. These states provide operational context: check the workload’s status and events as well as the container’s output when investigating what is happening.
Configuration, Data, and Image Identity
Configure the same image for different environments
Runtime settings let an image be used in different environments without building a different image for every setting. Docker can supply environment variables, command arguments, port mappings, and mounted files or directories. For example:
docker run --name app -d \
-e APP_MODE=production \
-p 8080:8080 \
--mount type=volume,source=app-data,target=/var/lib/app \
example/app:1.0
This command names the container app, runs it in the background, supplies APP_MODE=production, maps host port 8080 to container port 8080, and mounts the app-data at /var/lib/app inside the container. Supplying a setting is not enough by itself: the application must be written to read APP_MODE and use the mounted path.
The keeps persistent data separate from the container’s writable layer. As a result, replacing the container need not erase data held in that volume.
Treat credentials and image identity deliberately
Environment variables are convenient for ordinary settings, but they are not a secure secret store. Someone with sufficient access to inspect a container may be able to read them. Use an appropriate secrets-management mechanism for credentials.
Keep configuration explicit and reviewable, including which image is being run. Pin an image to a specific version, or use a digest when stronger immutability is needed. A tag may point to a different image later, so relying on a tag alone may not identify the same image over time.
Resource Controls and Performance
Set controls from observed needs
Without resource limits, a busy or leaking container can compete with other workloads for host resources. Set limits according to measured application needs, then monitor performance after applying them. The source’s Docker example is:
docker run --name app -d \
--memory=512m \
--cpus=0.5 \
example/app:1.0
This sets a memory limit of 512 MiB and restricts the container to half of one CPU’s capacity. These controls can have different effects: exceeding a hard memory limit can cause a process to be killed, while a CPU limit can constrain throughput. A softer memory reservation is also available in Docker, but it does not guarantee that usage will stay below the reservation.
Limits set too low may lead to slow responses, restarts, or failures. Those symptoms do not by themselves show that a limit is the cause. Check metrics and exit details before deciding whether to change a limit; after changing it, continue monitoring performance.
Kubernetes scheduling and limits
Kubernetes also uses resource requests and limits, but they play distinct roles. Requests help the scheduler decide where a can fit; limits constrain resource use. If no suitable node has enough capacity for a ’s requests, the may remain pending. A container can be terminated after exceeding a memory limit. Thus, a pending and a memory-limit termination point to different resource-related situations and call for checking the relevant scheduling or runtime evidence.
Logging, Visibility, and Troubleshooting
Collect and manage logs
Applications should normally write diagnostic output to standard output and standard error so the runtime can collect it. For Docker, this command displays the most recent 100 lines and continues following new output:
docker logs --tail 100 --follow app
Docker’s logging driver determines how are stored or forwarded. The default json-file driver can use substantial disk space if logs grow without rotation, so configure rotation or choose a driver that manages log volume. Changing the daemon’s default logging configuration affects newly created containers, not existing ones. Centralized logging is useful when containers run across multiple hosts or need longer-term retention.
Logs are one part of operational visibility, not a complete diagnosis. Combine them with container status, restart counts, resource metrics, and runtime events. In Kubernetes, kubectl logs retrieves container output; cluster-level logging commonly sends logs to a central store.
Troubleshoot by gathering evidence first
Work through the available evidence before changing settings:
Check status and exit details. Use
docker ps -ato include stopped containers, thendocker inspect appto examine the container’s state and configuration.Read the logs. Use
docker logs app. Look for startup errors, missing configuration, failed connections, and when the first failure occurred.Check dependencies and connectivity. Confirm that required services are running and reachable, and that the expected host-to-container port mappings are in place.
Check resource pressure. Use
docker stats appand inspect host capacity. A memory-limit failure may appear as an out-of-memory termination; sustained CPU pressure may appear as latency or slow progress.Make one targeted change, then verify. Choose a change supported by the evidence—for example, correcting a missing setting, fixing a mount path, or adjusting a justified resource limit. Record the change and confirm that the container remains healthy.
For a Kubernetes workload, use kubectl describe <> to inspect status and events, and kubectl logs <> to inspect application output. A container in is repeatedly restarting, but that state alone does not identify why. Possible causes include application errors, bad configuration, insufficient resources, or failing health checks; inspect logs and events to investigate rather than treating the restart state as the root cause.
: A includes creating, starting, running, stopping, and removing a container.
: Pinning an image means specifying its identity explicitly, such as by version or digest.
: A resource request indicates capacity used in scheduling decisions; a resource limit constrains resource use.