Container Image Types and Sizes
What are Container Image Variants?
When selecting a Docker image, developers encounter multiple variants with names like slim, alpine, full, or version-specific tags. These variants represent different base images with varying sizes, dependencies, and capabilities. Understanding these differences is crucial for creating efficient, production-ready containers.
Container image size directly impacts:
- Build time - Larger images take longer to pull and push
- Deployment speed - Smaller images deploy faster in production
- Storage costs - Cloud registries often charge per gigabyte stored
- Functionality - Smaller images may lack tools needed for development or troubleshooting
Image Size Comparison
graph LR
A["Alpine
5-50 MB"] -->B["Slim
100-200 MB"]
B -->C["Standard/Full
500 MB - 2+ GB"]
style A fill:#90EE90
style B fill:#FFD700
style C fill:#FF6B6B
Base Image Types
Alpine
The smallest and most lightweight option. Alpine Linux is a minimal Linux distribution containing only essential components.
Characteristics:
- Size: 5-50 MB (extremely small)
- Package manager:
apk(different from standard Linux) - Use case: Microservices, production deployments where size matters
- Trade-off: Limited tools, may require custom installation
Example - Python Alpine:
# Alpine variant
FROM python:3.9-alpine
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]
Image size: ~100 MB vs ~900 MB for standard Python image.
Slim
A middle-ground option that removes non-essential packages while keeping common development tools.
Characteristics:
- Size: 100-300 MB (significantly smaller than standard)
- Includes common utilities (curl, git, etc.)
- Package manager: Standard Linux package managers
- Use case: Balance between size and functionality
Example - Node.js Slim:
FROM node:18-slim
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]
Image size: ~150 MB vs ~900 MB for standard Node.js.
Standard/Full
Complete images with development tools, debuggers, and additional libraries pre-installed.
Characteristics:
- Size: 500 MB - 2+ GB
- Includes development tools (apt-get, make, build-essentials, etc.)
- Use case: Development environments, debugging, complex applications
- Trade-off: Larger images, slower deployments
Example - Node.js Standard:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]
Image size: ~900 MB (includes development tools).
Linux-Based vs Specialized Containers
Linux-Based Images (Ubuntu, Debian, Alpine)
Standard Linux distributions used as base images.
# Ubuntu-based (larger, full-featured)
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y python3 python3-pip
# Debian-based (smaller than Ubuntu)
FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y python3 python3-pip
# Alpine-based (smallest)
FROM alpine:latest
RUN apk add --no-cache python3
Size comparison:
- Ubuntu: ~77 MB base
- Debian: ~50 MB base
- Alpine: ~7 MB base
.NET Container Images
Microsoft provides optimized .NET images with different variants.
Runtime Image (Production - contains only runtime):
FROM mcr.microsoft.com/dotnet/runtime:7.0
WORKDIR /app
COPY --from=builder /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]
Size: ~100-200 MB (contains only .NET runtime).
ASP.NET Image (For web applications):
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=builder /app/publish .
EXPOSE 80
ENTRYPOINT ["dotnet", "MyWebApp.dll"]
Size: ~200-300 MB (includes ASP.NET runtime and web hosting).
SDK Image (Development - includes build tools):
FROM mcr.microsoft.com/dotnet/sdk:7.0
WORKDIR /app
COPY . .
RUN dotnet publish -c Release -o publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0
COPY --from=builder /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]
Size: ~2+ GB (includes compiler, build tools, debuggers).
Multi-Stage Builds: Optimizing Image Size
Multi-stage builds use one image for compilation and another (smaller) image for runtime.
# Stage 1: Build (large image with build tools)
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder
WORKDIR /src
COPY ["MyApp/MyApp.csproj", "MyApp/"]
RUN dotnet restore "MyApp/MyApp.csproj"
COPY . .
RUN dotnet publish -c Release -o /app/publish
# Stage 2: Runtime (small image, only runtime needed)
FROM mcr.microsoft.com/dotnet/runtime:7.0
WORKDIR /app
COPY --from=builder /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]
Result:
- Build stage: 2+ GB
- Runtime stage: 150-200 MB
- Final image: Only 150-200 MB (no build tools included)
Practical Comparison: Multi-Purpose Application
Consider a Python web application with specific dependencies:
graph TD
A["Python Application
Decision Matrix"] -->B{What is
primary use?}
B -->|Production| C["Use Alpine/Slim
50-200 MB"]
B -->|Development| D["Use Standard
500+ MB"]
B -->|CI/CD| E["Use Slim
100-300 MB"]
C -->C1["Minimal overhead
Fast deployment"]
D -->D1["Full debugging tools
Slower startup"]
E -->E1["Balance of both
Reasonable size"]
style C fill:#90EE90
style D fill:#FF6B6B
style E fill:#FFD700
Image Selection Guidelines
| Use Case | Recommended | Size | Reasoning |
|---|---|---|---|
| Production microservices | Alpine/Slim | 50-200 MB | Fast deployment, minimal attack surface |
| Production monolith | Slim | 150-300 MB | Still small, more tools available |
| Development environment | Standard | 500+ MB | Full tooling for debugging and development |
| CI/CD build pipeline | Slim | 100-300 MB | Quick builds, sufficient for compilation |
| High-security apps | Alpine | 5-50 MB | Minimal dependencies reduce vulnerabilities |
Common Pitfalls
- Using standard images in production - Larger images increase deployment time and costs
- Using Alpine without testing - Missing packages may cause runtime failures
- Forgetting multi-stage builds - Build tools get included in final image unnecessarily
- Not cleaning up package managers - Cache from
apt-getorapkincreases image size
Always test image variants thoroughly before production deployment.
Key Takeaways
- Alpine and Slim images are ideal for production-smaller size means faster deployment and lower costs
- Standard images include development tools; use them for local development and debugging
- Multi-stage builds separate compilation from runtime, reducing final image size
- .NET provides Runtime, ASP.NET, and SDK variants optimized for different deployment scenarios
- Image selection significantly impacts deployment speed, storage costs, and security
- Always test image variants thoroughly before production deployment
- Use docker image ls to audit current images and identify optimization opportunities
Next Steps: Evaluate current container images using docker image ls --format "table {{.Repository}}\t{{.Size}}" to identify optimization opportunities, then refactor Dockerfiles using multi-stage builds for production applications.