ENTRYPOINT defines the fixed executable; CMD supplies default arguments to that entrypoint (or the full command if no ENTRYPOINT). If both exist, CMD args are appended to ENTRYPOINT. Override: docker run --entrypoint replaces ENTRYPOINT; trailing args replace CMD.
FROM scratch or distroless for Go/static binaries.
package.json before source so dependency install caches when only code changes.
latest can change). Digest (SHA256) identifies an exact image content. Pinning by digest ensures reproducible deploys and prevents supply-chain surprises when a tag is retagged. Trade-off: you must bump digest explicitly for updates.
tini, dumb-init) or ensure the app handles signals and children correctly.
--cpus, --memory, or in Compose/Kubernetes: resources.limits. cgroups enforce limits. Without limits, a container can starve the host. Set requests (guaranteed) and limits (cap) in orchestrators for scheduling and stability.
host mode shares the host network stack (no isolation). none disables external networking.
EXPOSE is documentation/metadata only - it does not open firewall or publish ports. Publishing requires -p or Compose ports:. EXPOSE helps humans and orchestrators understand intended ports.
docker network inspect), DNS names, correct listen address inside app (0.0.0.0 not only localhost). Use docker exec ping/nslookup, tcpdump, check iptables and whether firewalld blocks published ports.
docker rm unless data is in a volume or bind mount. Images stay; anonymous volumes may be orphaned unless removed with -v.
tmpfs stores data in memory - fast, ephemeral, never hits disk. Good for sensitive temp files, cache, or reducing disk I/O. Lost on container restart - not for durable data.
/. Pair with tmpfs for /tmp and writable volumes only where needed. Kubernetes: readOnlyRootFilesystem: true in security context.
user namespaces, or adjusting host permissions. On rootless Docker, subuid/subgid mapping matters.
docker compose up orchestrates lifecycle on a single host (or Swarm with legacy compose v3 deploy).
depends_on only orders start - not readiness. A DB container may start before it accepts connections. Use healthcheck + depends_on: condition: service_healthy (Compose v2+) or retry logic in apps.
ARG for secrets in layers that persist - build args can leak in image history.
.git, secrets, or node_modules when not needed. Same idea as .gitignore for Docker builds.
docker-compose.override.yml) mounting source for dev. Avoid running dev images in production.
USER), drop Linux capabilities, read-only root FS, no privileged mode, minimal base images (Alpine/distroless), scan images for CVEs (Trivy, Grype), pin base image digests.