What is Docker and what problem does it solve?
Fast recall
Quick revision
Core answer
Interview-ready guide
Interview answer
Docker is a platform and toolchain for building images and creating isolated containers. An image contains application files, user-space dependencies, and runtime configuration. When a container is created, the runtime adds isolation, networking, mounts, resource controls, and a writable layer while sharing the hosting kernel.
For example, CI can build one Spring Boot image from a pinned JRE base, run tests/scans, and promote the same image digest through staging and production. Each environment supplies its own database address and secrets rather than changing the JAR inside the container.
This reduces the 'works on my machine' problem, but it does not make every machine identical. CPU architecture, kernel, runtime configuration, volumes, networks, and external services can still differ. Docker solves repeatable packaging and container lifecycle; orchestration, persistent data, security policy, monitoring, and application correctness remain separate responsibilities.
What is Docker and what problem does it solve
Direct Answer
Docker is a platform and toolchain for building images and creating isolated containers. An image packages application files, user-space dependencies, and runtime configuration; the container still uses the hosting kernel and external services. This reduces environment drift and makes delivery repeatable, but it does not guarantee identical behavior across CPU architectures, kernels, configuration, data, or networks.
Code Example
// Dockerfile for a Spring Boot app
FROM eclipse-temurin:17-jre-alpine
// Create app directory
WORKDIR /app
// Copy the JAR built by Maven/Gradle
COPY target/order-service-1.0.0.jar app.jar
// Expose port Spring Boot uses
EXPOSE 8080
// Run the application
ENTRYPOINT ["java", "-jar", "app.jar"]
// Build command: docker build -t order-service:1.0 .
// Run command: docker run -p 8080:8080 order-service:1.0
// Your Spring Boot app now runs in isolation
// with Java 17 guaranteed, regardless of host OS
Common Mistakes & Pitfalls
- Confusing containers with VMs: Freshers often think Docker is a lightweight virtual machine. Containers share the host OS kernel and start in milliseconds, while VMs virtualize hardware and take minutes to boot.
- Copying the entire project folder: Beginners write
COPY . /appin Dockerfiles, including source code, .git folders, and IDE files. Only copy the compiled JAR—Docker images should contain the production artifact, not development clutter. - Running as root user: Default Docker containers run as root, which is a security risk. Production Dockerfiles should create a non-root user and switch to it before running the application.
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.