Docker Fundamentals: Image Layers, Container Operations, and Compose Networking
ENGINEERING NOTES
Published / DavidHLPL
Docker appears in the 7 notes across the two repositories as operational checklists: Dockerfile, layers, volumes, networking, and Compose. This page compresses the checklist into a minimal usable model, clarifies when to use volume vs bind, bridge vs host, and the value of Compose, without dumping images verbatim.
Core Mechanism
1. Image layers are the unit of caching and reuse
| Concept | Role | Boundary |
|---|---|---|
| Base Image | Shared read-only layer | Do not write mutable data into image layers |
| Layer | One layer per Dockerfile instruction | Too many small layers add metadata overhead |
| Build cache | Hits can skip rebuilds | COPY order affects hit rate |
The source notes Layer和BaseImage概念.md (Layer and Base Image) shows layers via docker history, while Dockerfile基础.md (Dockerfile Basics) explains the layer effects of FROM/RUN/COPY. In practice, put immutable dependencies first and mutable source code last to maximize cache hits.
2. Container operations and data lifecycle
docker run/stop/start/rm/rmimanage container and image lifecycles; the sourceDocker常见命令.md(Docker Common Commands) listssave/load/push/pull.- Volumes: a
volumeis managed by Docker, easily shared across containers and backed up; abind mountdirectly maps a host path, suitable for dev hot-reload but coupled to the host. - Choice: use
volumewhen you need portable, persistent data; usebindwhen you need to edit host files directly; do not bind database files to a temporary directory.
3. Networking and Compose orchestration
容器网络连接.md(Container Networking) distinguishesbridge(default isolation),host(shares host networking),none, and custom networks; custom networks support container-name DNS.DockerCompose.mddeclaresservice/network/volumeindocker-compose.yml;up/down/ps/logs/build/pullcovers single-host multi-container. Compose fits dev/test and small production, not a replacement for K8s scheduling and health checks.
Applicability
- Single host or small cluster that needs declarative orchestration without K8s.
- Images can be layer-cached; runtime data needs
volumepersistence. - Containers need DNS-reachable custom networks.
Not Applicable and Risks
- Multi-host scheduling, rolling updates, and health gates are better served by orchestrators beyond Compose (e.g., K8s);
multi-service-readinessclarifiesreadinessvs runtime distinction. docker commitbaking a running container into an image loses Dockerfile traceability; prefer rebuilding.- Bind mounts expose host paths; evaluate permissions and SELinux/AppArmor in production.
Minimum Verification
- After
docker build, rundocker historyto confirm layer count and cache hits. - Mount with
volumeandbindrespectively, restart containers, and verify data persistence. - Validate
docker-compose config, then runup -d, inspectpsandlogs, and confirm the services are reachable.
Evidence and Uncertainty
- Source facts:
ingest-docker-fundamentalscaptures 7 source notes on commands, volumes, and networking verbatim. - Synthesis: This page compresses the checklist into a layer—data—network model and gives
volume/bindselection criteria. - Unconfirmed: Image size, build time, and network performance were not measured; the
versionfield in Compose is now optional, and version differences in sources were not exhaustively verified.
Related Pages
Sources and related documents
Research notes
- Original document: src/content/note/en/docker-fundamentals.md
- Source revision: f49953fb0d4bd52a39bf81167b0c4b7dd7d78a64
- Evidence status: active