Practical tips for building, running, troubleshooting, and securing containers. From the basics to Compose Watch, Docker Scout, and the latest AI tools in Docker Desktop.

Example: docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" — show only the information you actually need instead of the full default table.
Example: docker system prune -a --volumes — removes stopped containers, unused networks, dangling images, and volumes that aren't in use. Use with caution in production.
Example: docker exec -it container_name /bin/bash — drop into a running container to troubleshoot without stopping it.
Multi-stage builds separate the build environment from the production environment. Example: build with a full SDK image in the first stage, then copy only the compiled artifact into a minimal runtime image in the final stage.
Example: use python:3.14-slim instead of python:3.14 — fewer packages means fewer known vulnerabilities (CVEs) and a smaller image size.
Put commands that rarely change (e.g. apt install) early in the Dockerfile and commands that change often (e.g. COPY . .) last — that maximizes how much Docker can reuse from the cache.
Example: docker compose up --watch — Compose Watch syncs source changes straight into running containers and rebuilds when needed, eliminating the manual edit-build-run cycle.
Example: docker compose -f compose.yaml -f compose.prod.yaml up — let a base file hold what's shared and override files handle environment-specific differences.
Example: mark non-critical services (e.g. an email-testing tool, a search engine) with profiles: ["debug"] in the compose file so they only start with docker compose --profile debug up.
Example: docker network create my-project-net — keep containers for different projects separated so they can't accidentally reach each other.
Within the same Docker network, containers can reach each other by service name (e.g. db or redis) thanks to built-in DNS — never hardcode IP addresses between containers.
Example: docker run -p 127.0.0.1:8080:80 nginx — bind to localhost instead of all interfaces (0.0.0.0) if the service shouldn't be reachable from outside.
Example: docker volume create my-data and mount with -v my-data:/var/lib/data — Docker manages the lifecycle better than direct paths into the host's filesystem.
Example: -v $(pwd)/src:/app/src — mirror local source code straight into the container so changes show up immediately without a rebuild.
Example: docker run --rm -v my-data:/data -v $(pwd):/backup ubuntu tar czf /backup/backup.tar.gz /data — archive a volume's contents to a local file without extra tooling.
Example: docker scout cves myimage:1.0 — catch known vulnerabilities early in the development workflow instead of discovering them in production.
docker sbom is deprecated in favor of docker scout sbom — update any scripts or pipelines that still use the old command.
Example: add USER node (or create your own restricted account) in the Dockerfile — limits the damage if a container gets compromised.
Example: docker images myimage --format "{{.Size}}" — compare the size before and after a Dockerfile change to confirm an optimization actually helped.
Example: HEALTHCHECK CMD curl -f http://localhost:3000/health || exit 1 — a container that's "running" isn't the same as a container that can actually handle traffic.
Every RUN, COPY, and ADD creates a new layer. Combine related commands where it makes sense to keep the image both smaller and faster to pull.
Example: docker inspect container_name --format '{{.State.ExitCode}}' together with docker logs container_name usually gives you the full picture of what went wrong.
Example: docker run -it --entrypoint sh myimage — start a new instance with an interactive shell instead of the default command, to explore the filesystem manually.
Docker Desktop's built-in AI agent Gordon can analyze why a container is exiting unexpectedly or why a build is underperforming — worth asking before you dig in manually.
docker sbx (Docker Sandboxes) runs an AI coding agent — Claude Code, Codex, Gemini CLI, and similar tools — inside an isolated container instead of directly on your machine, so the agent can read, edit, and run code without full access to your host filesystem or network. Worth reaching for whenever you're letting an agent operate somewhat autonomously and want a hard boundary around what it can touch.
Synchronized file shares give significantly faster filesystem performance for Windows developers running Linux containers via WSL2, compared to a traditional bind mount across the Windows/Linux boundary.
The older osxfs sharing system has been fully phased out in favor of VirtioFS, which delivers better performance and avoids unnecessary file-ownership overhead.
Example: build the builder stage separately and cache it between runs — only changed layers need rebuilding, which can cut pipeline times in half.
Example: docker build -t myregistry/app:$(git rev-parse --short HEAD) . — makes it possible to trace exactly which code is running in a given environment.
Add docker scout cves as a step in CI before pushing to the registry — stop vulnerable images before they ever reach production.
Example: docker swarm init followed by docker service create --replicas 3 myimage — built-in orchestration without having to stand up a full Kubernetes cluster for smaller workloads.
Example: docker service update --image myimage:2.0 --update-parallelism 1 --update-delay 10s myservice — rolling update, one instance at a time.
Before manifests go to a production cluster, test them locally against Desktop's integrated Kubernetes cluster for faster iteration.
Example: docker model pull ai/smollm2:360M followed by docker model run ai/smollm2:360M — prototype against a language model locally without depending on external APIs or sending data to a third party.
Docker Model Runner now supports registry mirrors, making it faster and more reliable to pull models in environments with limited or unstable internet connectivity.
Docker MCP Toolkit runs Model Context Protocol servers in containers, giving AI tools access to resources without installing them directly on the host machine — easier to sandbox and clean up.
Example: docker run --restart unless-stopped myimage — let Docker automatically restart the container on crash or host reboot, except when you've stopped it manually yourself.
Example: docker run --log-driver json-file --log-opt max-size=10m --log-opt max-file=3 myimage — stops container logs from growing unbounded and filling the disk.
Build the same image for every environment and inject environment-specific configuration via environment variables or compose files — avoid building different images for test, staging, and production.
Related guides: 100+ Tips & Tricks — Ubuntu Server 26.04 LTS, 100+ Linux Commands. All free guides are in the library.