Docker & Containers (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What are Distroless and Alpine base images, and what are their trade-offs (`glibc` vs `musl libc`)?
senior LevelCode ExampleDocker & ContainersSystem Design
In Simple Words:
- Alpine Linux (
alpine):- Uses
musl libcand BusyBox. Extremely small (~5MB base). - Trade-off:
musl libchas known performance overhead with certain memory allocators, and compiled native C-extensions (like Pythonnumpy, Nodegrpc, or Rust FFI bindings) may require compilation from source if pre-built wheels targetingmuslare unavailable.
- Uses
- Distroless Images (GoogleContainerTools):
- Contains only your application and runtime dependencies. No package managers (
apk,apt), no shells (/bin/sh,/bin/bash), and no standard Unix utilities. - Built with standard
glibcfor maximum binary compatibility. - Trade-off: Exceptional security (attackers cannot open a reverse shell or download malware), but local interactive debugging requires
crictlor ephemeral debug containers.
- Contains only your application and runtime dependencies. No package managers (
dockerfile
# Using Google Distroless for Node.js
FROM gcr.io/distroless/nodejs20-debian12
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
USER nonroot:nonroot
CMD ["dist/server.js"]