Use this when scripting Docker CLI commands.
Docker CLI
The Docker CLI (docker build, run, ps, logs, exec, push) is the command-line way to manage images and containers, easy to script but best combined with Compose or IaC for repeatable setups.
1. Docker CLI for scripting container operations.
2. Use --format for parsing.
3. Prefer Compose/orchestrators over raw docker run in production.
4. Health checks.
5. Clean up unused objects.
script → docker CLI → daemon → containers
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as mutable tags, orphaned containers/networks, volume data loss, environment drift, restart loops, port collisions and running container mistaken for healthy application, choosing the cases most relevant to Docker context/daemon identity, image/container IDs, exit status, detached versus foreground state and inspect/read-back after mutation. For Container Automation → Docker CLI, the evidence must connect the control-plane result to the container/service plus attached networks, volumes and external dependencies and explain any gap between desired, controller-reported and consumer-visible state.
Step 2 Common mistakes Narrow the fault
docker runcommands kept only in shell history.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- The Docker CLI is easy to script but not declarative.
- Check exit codes of each command.
- Move repeated setups to Compose or IaC.
docker ps -a --format '{{.Names}} {{.Status}}'— containersdocker inspect <c> --format '{{.State.Health.Status}}'— healthdocker logs --tail 50 <c>— logs
ReferenceWhy it matters1 section · depth on demand
In depth
The Docker CLI builds images, runs and inspects containers, and manages networks and volumes. In automation it appears in CI pipelines (build and push images), in scripts that run tools in containers, and in troubleshooting.
docker build -t registry.example.com/net-tools:1.4.0 .
docker push registry.example.com/net-tools:1.4.0
docker run --rm -v "$PWD":/work -w /work registry.example.com/net-tools:1.4.0 ansible-lint
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Image}}'
docker logs --since 10m netbox
docker exec -it netbox /bin/bash
docker system df && docker image prune -f
Running tools in versioned containers (docker run --rm) gives the same environment on every machine. Use --format and --quiet options for script-friendly output instead of parsing tables.
ReferenceImportant terms & boundaries1 section · depth on demand
Mechanics
Container Automation → Docker CLI is owned at runtime by the Docker/OCI container engine and orchestration/Compose client applying image, network and volume intent. The linked authority for bounded mechanics is Docker Documentation; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Container Automation > Docker CLI. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.docker.com/ · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For Docker context/daemon identity, image/container IDs, exit status, detached versus foreground state and inspect/read-back after mutation, prefer typed fields and stable IDs over human presentation text.