Skip to primary content
DevOps Technical Tutorial

Docker Explained: Containerization, Namespaces, Cgroups & Multi-Stage Builds

Comprehensive Docker guide: kernel namespaces, cgroups, layered image filesystems, writing optimized multi-stage Dockerfiles for Java and Node.

DevOps
# Multi-stage Dockerfile for Spring Boot Application
# Stage 1: Build JAR using Maven
FROM maven:3.9-eclipse-temurin-21-alpine AS builder
WORKDIR /app
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn clean package -DskipTests

# Stage 2: Minimal Production JRE Image
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app
COPY --from=builder /app/target/*.jar app.jar
EXPOSE 8080
USER 1000:1000
ENTRYPOINT ["java", "-jar", "app.jar"]

1. Containers vs. Virtual Machines

A Virtual Machine runs a full guest operating system on top of a hypervisor, consuming gigabytes of memory and requiring minutes to boot. Docker containers share the host Linux kernel, isolating processes using two fundamental Linux kernel features:

  • Namespaces: Isolate view of system resources (PID, NET, MNT, IPC, UTS).
  • Control Groups (cgroups): Meter and limit hardware consumption (CPU, RAM, I/O bandwidth).

2. The Power of Multi-Stage Builds

Multi-stage builds allow developers to compile source code in a heavy build environment with compilers and SDKs, then copy only the compiled binary into a lightweight production runtime image, reducing image size from 800MB to under 120MB.

Key Engineering Takeaways
  • Docker images use immutable, cached layers; order Dockerfile steps from least-frequently changed to most-frequently changed.
  • Never run container processes as root; declare a dedicated non-root USER.
  • Multi-stage builds dramatically shrink attack surface and download times.

Frequently Asked Questions

What is the difference between CMD and ENTRYPOINT?
ENTRYPOINT sets the primary executable to run, while CMD provides default parameters that can be overridden by arguments passed to docker run.
Master This in Our Ghaziabad Coding Labs

Gain deep mastery over these concepts with direct instructor guidance, code reviews, and mock interviews at C-60 R.K Tower, 3rd Floor, RDC, Ghaziabad.

Explore Related Course Call 7503962162
Physical Training Center

Visit Our Ghaziabad Training Center

Join classroom batches, attend interactive lab sessions, code with mentors, and take advantage of our high-speed dev workstations.

Campus Address:
C-60 R.K Tower, 3rd Floor, RDC, Ghaziabad, Ghaziabad, Uttar Pradesh
Direct Counseling Helpline:
Call 7503962162
Get Google Maps Directions Call Now: 7503962162 Explore Ghaziabad Training Hub
Call 7503962162 Get Course Details