What Is Docker? A Beginner's Guide to Container Technology
Bury the phrase "it worked on my machine." Docker packages your application with all its dependencies, guaranteeing it runs the same way in every environment.
What Is Docker?
Docker is a platform for running applications in lightweight, isolated environments called containers. A container includes everything the application needs: code, runtime, libraries, and system tools.
Containers vs Virtual Machines
| Feature | VM | Container | |---------|-----|-----------| | Startup time | Minutes | Seconds | | Size | GBs | MBs | | Resource usage | High | Low | | Isolation | Full | Process-level | | Portability | Medium | High |
Core Concepts
Dockerfile
The recipe that defines how to build your container:
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
Image — Immutable template built from a Dockerfile (layered storage)
Container — Running instance created from an Image
Docker Compose
Managing multiple containers together:
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
depends_on:
- db
db:
image: postgres:16-alpine
environment:
- POSTGRES_DB=myapp
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
Best Practices
1. Use Small Base Images
Alpine-based images (130MB vs 1.1GB).
2. Multi-stage Builds
Separate build and production stages to minimize final image size.
3. Use .dockerignore
Exclude node_modules, .git, .env, and other unnecessary files.
4. Optimize Layer Order
Put frequently changing files last to leverage caching.
Essential Commands
| Command | Purpose |
|---------|---------|
| docker build | Build image |
| docker run | Start container |
| docker ps | List running containers |
| docker logs | View logs |
| docker exec -it | Enter container |
| docker compose up -d | Start all services |
| docker system prune | Clean unused resources |
Conclusion
Docker is a cornerstone of modern software development. It provides environment consistency, portability, and deployment simplicity. "Works on my machine" becomes "works everywhere."
Learn Docker and container technologies on the DevOps career path at LabLudus.