Docker
Packaging a Spring Boot or Next.js app so it runs identically on your laptop and in production.
1.5 hrOverview
Docker packages an application together with everything it needs to run — the runtime, dependencies, and configuration — into a single image that behaves identically on your laptop, a CI runner, and a production server.
Why it matters
"It works on my machine" stops being a valid excuse once the machine is a container image. Docker eliminates an entire class of environment-mismatch bugs (wrong Java version, missing native library) by shipping the exact runtime the app was tested against.
How backend developers use it
A multi-stage Dockerfile for a Spring Boot service: one stage compiles the JAR with Maven, a second stage copies only the built JAR into a slim JRE base image. This keeps the final image small — you don't ship the Maven build tool or source code to production, just the runnable artifact.
Common mistakes
Warning
Single-stage builds that ship the full JDK, build tools, and source code in the production image — often 3-4x larger than necessary.
Warning
Running the container process as root instead of a dedicated non-root user, widening the blast radius if the container is ever compromised.
Warning
Not pinning a base image version (FROM eclipse-temurin:latest) — "latest" changes underneath you and breaks reproducible builds.
Warning
Baking secrets into the image with ENV or ARG instead of injecting them at runtime — anyone who can pull the image can read them.
Example commands
Build an image from the Dockerfile in the current directory
docker build -t myapp:1.0 .
Run a container, mapping host port 8080 to container port 8080
docker run -p 8080:8080 myapp:1.0
See what's running
docker ps
Tail logs from a running container
docker logs -f <container_id>
Shell into a running container to debug
docker exec -it <container_id> sh
Resources
Retrieval check
Before you continue
- Explain what this tool or practice changes in the delivery lifecycle.
- Name one common failure it helps you diagnose or prevent.
- Repeat one example command from memory, then verify it.