27 / 75 · 08 Infrastructure as Code Testing · Minimal Container Images← prev⊞ allnext →☰ Read as one page
5.5Alpine Images: Smaller but with Tradeoffs
Alpine Linux uses musl libc instead of glibc, which causes compatibility issues with some applications. Understand the tradeoffs before choosing Alpine.
When Alpine Works Well
- Pure JavaScript/TypeScript Node.js applications (no native addons)
- Go applications compiled with CGO_ENABLED=0
- Simple Python applications without C extensions
- Utility containers (curl, wget, debugging tools)
When Alpine Causes Problems
- Python packages with C extensions (numpy, pandas, scipy) -- compilation is slow and sometimes fails
- Node.js packages with native addons (bcrypt, sharp) -- need alpine-specific builds
- Applications that depend on glibc-specific behavior (DNS resolution edge cases)
- Java applications (use Eclipse Temurin JDK images instead)
# Alpine with native Node.js addons requires extra build tools
FROM node:24-alpine AS builder
# Need to install build tools for native modules
RUN apk add --no-cache python3 make g++
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
USER node
CMD ["node", "dist/server.js"]