Container Operations
Investigate container failures, release immutable images, protect persistent data, and reclaim space safely.
Operate containers as replaceable processes. Preserve evidence before restarting, and keep data recovery separate from container replacement.
Establish current state
Record the container name, image digest, state, exit code, health, restart count, and recent events.
Read logs before restarting
Container logs normally contain stdout and stderr from the main process. If the application writes only to files inside its writable layer, those logs can disappear with the container; configure the application to emit operational logs to stdout/stderr or a managed log destination.
Inspect from inside carefully
Avoid editing a running container to create a permanent fix. Capture the finding, update the image or Compose definition, and replace the container. Be careful with env: its output may contain credentials.
Deploy an immutable version
Record the resolved image digest. For rollback, set APP_VERSION to the last known-good artifact and repeat the same commands and verification. A single Compose replica can briefly stop during replacement; use multiple instances behind a load balancer when the service cannot tolerate that interruption.
Back up persistent data
A volume is not a backup. Use the database’s native backup tool for consistent database backups. For file data, coordinate application writes before copying and test restoration into a separate volume or environment.
Protect the dump as production data. Verify it with the corresponding restore tool in an isolated database before depending on it.
Reclaim space deliberately
Start with dangling images. Do not add --volumes or run broad docker system prune on a shared or unfamiliar host until every candidate has an owner and recovery plan.
Reduce runtime privilege
- Run the image as a non-root user.
- Avoid
privileged, host PID/network namespaces, host devices, and Docker socket mounts. - Drop capabilities the process does not need.
- Use a read-only root filesystem with explicit writable paths.
- Set CPU, memory, process, and log limits appropriate to the workload.
- Keep the engine, host kernel, base images, and application dependencies patched.