Use it for day-to-day container operations on a Docker host.
Docker & Compose Operations
Docker and Compose operations: running, inspecting, updating and cleaning up containers and multi-container stacks on a single host with the docker CLI and docker compose.
1. docker compose ps — services healthy?
2. docker compose logs -f <svc>.
3. Update: docker compose pull && docker compose up -d.
4. Disk: docker system df.
5. Daemon: journalctl -u docker.
compose file → images pulled → containers (re)created → healthchecks → logs
Frequent problems are stale environment values, unintended anonymous volumes, dependency assumptions based only on startup order, restart loops hiding the original failure, healthchecks that test the wrong layer, and manual container changes that drift from Compose intent. Preserve the first divergent observation and repeat the same bounded verification after remediation.
Continue only after interpreting the current observation.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 workflow Verify boundary
Validate the rendered Compose configuration before applying it, then inspect created containers, networks, mounts and environment. Check health status, restart count, exit code and application logs, and verify the externally consumed service path after any recreate or image change.
Step 2 Failure signatures and limits Narrow the fault
Frequent problems are stale environment values, unintended anonymous volumes, dependency assumptions based only on startup order, restart loops hiding the original failure, healthchecks that test the wrong layer, and manual container changes that drift from Compose intent.
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.
Subtopics
Go one level deeper into this subject.
Docker Compose defines a multi-container application in compose.yaml and manages it as one project with docker compose up, ps, logs and down.
Subtopic Container Logs and Log DriversDocker captures container stdout and stderr through a log driver; json-file is the default and needs rotation limits.
Subtopic Container Restart PoliciesRestart policies (no, on-failure, always, unless-stopped) tell Docker whether to restart a container when it exits or the daemon restarts.
Use Compose files in version control. Update with docker compose pull && docker compose up -d. Clean up carefully (docker system prune removes stopped containers and unused data).
docker compose ps— stack statusdocker ps -a— containers and exit codesdocker logs <c>— container outputdocker inspect <c>— config, mounts, network, state
ReferenceWhat it is1 section · depth on demand
Operating model
Docker & Compose Operations covers practical single-host and small-stack operation: declaring services, networks, volumes and environment, then using Docker/Compose state to create, inspect, update and remove workloads predictably. Compose is desired configuration for a group of containers, not a cluster scheduler.
ReferenceHow it works1 section · depth on demand
In depth
Docker and Docker Compose are the everyday tools for building images and running containers on a single host. Compose describes multi-container applications in a YAML file so they start, update and stop together.
Core commands:
| Task | Command |
|---|---|
| Build/tag/push | docker build -t img:tag ., docker push img:tag |
| Run | docker run -d --name app -p 8080:80 img:tag |
| Inspect | docker ps, docker logs -f app, docker inspect app |
| Shell in container | docker exec -it app sh |
| Compose up/update | docker compose up -d, docker compose pull && docker compose up -d |
| Compose status/logs | docker compose ps, docker compose logs -f svc |
| Clean up | docker system df, docker image prune |
Operational practices: pin image versions in Compose files, keep secrets in env files or Docker secrets outside Git, define health checks and restart policies (restart: unless-stopped), and back up named volumes. For multi-host production workloads, an orchestrator (Kubernetes) replaces Compose.
ReferenceImportant terms & boundaries1 section · depth on demand
Scope map
- Docker CLI operational workflow
- Compose services
- Compose networks and volumes
- Environment/config handling
- Restart policies
- Healthchecks
- Logs and inspect output
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: Compose v2 plugin (docker compose). Replace images, ports and secrets handling for production.
services:
db:
image: postgres:16
environment:
POSTGRES_PASSWORD_FILE: /run/secrets/db_pw
secrets: [db_pw]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
retries: 10
volumes: [pgdata:/var/lib/postgresql/data]
api:
image: myorg/api:1.0
ports: ["8080:8080"]
depends_on:
db:
condition: service_healthy
secrets:
db_pw:
file: ./db_pw.txt
volumes:
pgdata: {}Expected output
docker compose psExpected state: Both services are running and db reports healthy before api starts.
NAME IMAGE SERVICE STATUS PORTS
app-db-1 postgres:16 db Up 2 minutes (healthy) 5432/tcp
app-api-1 myorg/api:1.0 api Up 2 minutes 0.0.0.0:8080->8080/tcp(healthy) comes from the healthcheck; Up alone only means the process started. Illustrative authored output: field layout matches the tool, values will differ in your environment.Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Documentation verification: confirms the upstream model used by the Topic. It does not assert local production behavior.
Basis: https://docs.docker.com/compose/ · confidence 92%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Docker & Compose Operations verification boundary matrix
A compact lookup separating intent, owning component state, effective state and consumer-visible outcome for Docker & Compose Operations.
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | Docker CLI operational workflow | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | Compose services / Compose networks and volumes | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | Environment/config handling | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | Restart policies | The original bounded check succeeds in the same time window | Production correctness outside this scope |