Complete Docker Runbook 2027: From Dockerfile to Production
Most Docker tutorials teach commands individually.
Build an image. Run a container. List the containers. Remove them.
Production operations rarely happen in that order.
You might inherit an existing service, investigate a failed deployment or discover that an application cannot access its database.
What helps in those situations is a repeatable operational workflow.
1. Understand the three main objects
Docker becomes easier to troubleshoot when you distinguish between three things:
| Object | Purpose |
|---|---|
| Dockerfile | Instructions for building an image |
| Image | Packaged application artifact |
| Container | An instance created from an image |
If application code changes, rebuild the image.
If runtime configuration changes, recreate the container with the appropriate configuration.
If you discover a fix while debugging inside a container, move that fix into source control rather than relying on manual modifications.
2. Build an image
From an existing application directory containing a valid Dockerfile:
docker build --pull -t myapp:1.0.0 . Inspect the result:
docker image ls myapp docker image inspect myapp:1.0.0 \ --format '{{.Id}} {{.Config.User}}' A useful Dockerfile should avoid unnecessary dependencies, exclude irrelevant build-context files and run the application as an appropriate non-root identity.
Use a .dockerignore file to keep local artifacts and sensitive files outside the build context.
For production, review and pin base image versions or digests.
3. Run a container with explicit limits
Assuming the example application listens on port 8000:
docker run -d \ --name myapp \ --restart unless-stopped \ --memory 512m \ --cpus 1.0 \ --pids-limit 200 \ -p 127.0.0.1:8080:8000 \ myapp:1.0.0 The resource values are illustrative. Choose limits that match the measured application requirements.
Binding to the loopback interface is useful when a host-level reverse proxy handles external traffic.
Check the container:
docker ps --filter name=myapp docker inspect myapp --format '{{json .State}}' The restart policy helps recover from certain process failures. It does not guarantee the application is healthy.
4. Debug before restarting
When a service fails, preserve its evidence.
docker ps -a --filter name=myapp docker logs --since 15m \ --timestamps --tail 200 myapp docker inspect myapp \ --format '{{json .State}}' If the container is still running:
docker stats --no-stream myapp docker top myapp Use interactive access only when necessary and authorized:
docker exec -it myapp sh This assumes the image contains a shell.
Minimal and distroless images may not provide one.
5. Understand persistent storage
Containers have writable layers, but those layers are removed with the container.
Data that must survive container replacement needs an explicit storage strategy.
Docker supports:
- Named volumes for Docker-managed persistent storage.
- Bind mounts for specific host paths.
- tmpfs mounts for temporary in-memory data.
Inspect available volumes:
docker volume ls docker volume inspect VOLUME_NAME A named volume using the default local driver remains tied to its Docker host. It does not automatically follow a container to another machine.
Document backups and restoration procedures separately.
6. Connect services through Docker networking
Applications communicating across containers should normally use a shared user-defined network.
Inspect an existing network:
docker network ls docker network inspect myapp-net Inside a container, localhost points to that container itself.
If your PostgreSQL service is named db on the shared network, the application should normally connect to db:5432.
Publishing the database port to the host is unnecessary when only application containers need access.
7. Manage a small stack with Compose
Modern Docker Compose uses the docker compose command.
Here is a small example:
services: web: image: myapp:1.0.0 ports: - "127.0.0.1:8080:8000" restart: unless-stopped mem_limit: 512m cpus: 1.0 Validate the configuration:
docker compose config Be careful when sharing resolved configuration because environment interpolation can expose credentials.
Deploy the example in an authorized environment:
docker compose up -d docker compose ps docker compose logs --tail 100 web Compose works well for small single-host applications. It is not a multi-host scheduler.
8. Ship an image through a registry
Using an illustrative private registry:
docker tag myapp:1.0.0 \ registry.example.com/team/myapp:1.0.0 docker push registry.example.com/team/myapp:1.0.0 Confirm the destination repository and its visibility before pushing.
Authenticate using approved registry credentials.
The image deployed to production should match the artifact tested in staging.
Record its registry digest rather than relying entirely on a mutable tag.
9. Include security in the workflow
Useful production controls include:
- Non-root application execution.
- Reviewed base images.
- Resource limits.
- Restricted Linux capabilities.
- Controlled secret injection.
- Image vulnerability scanning.
- SBOM and provenance metadata.
- Log rotation.
Test restrictions against the application's actual requirements before enforcing them.
A read-only filesystem is useful only when legitimate application writes have been accounted for.
10. Clean up carefully
Start with reporting:
docker system df docker system df -v docker volume ls docker ps -a These commands help establish what exists before you remove anything.
A volume without an attached container might still hold important application data.
Do not treat broad prune commands as an automatic response to a full disk.
Inspect log growth, build cache, image retention and application storage separately.
Final thoughts
A good Docker runbook is more than a command cheat sheet.
It explains what to inspect, what each operation changes and how to verify recovery.
For the full workflow, including Dockerfiles, registry examples, networking, Compose, security and troubleshooting scenarios, read:
Complete Docker Runbook 2027: Build, Run, Debug and Ship Containers
Official reference: Docker Engine documentation.
