What is Docker? — Container Platform Explained
What is Docker? — Container Platform Explained
Definition
Docker is an open-source platform that automates the deployment, scaling, and management of applications inside lightweight, isolated environments called containers. Containers package an application together with all its dependencies — code, runtime, system libraries, and configuration files — ensuring it runs consistently across any computing environment.
Docker was first released in 2013 and quickly became the industry standard for containerization, transforming how developers build, ship, and run software.
Containers vs Virtual Machines
Containers and virtual machines (VMs) both provide isolated environments for running applications, but they differ significantly in architecture and overhead:
| Aspect | Containers | Virtual Machines |
|---|---|---|
| OS Overhead | Share host OS kernel | Each VM runs a full guest OS |
| Startup Time | Milliseconds | Minutes |
| Size | Megabytes | Gigabytes |
| Isolation | Process-level | Hypervisor-level |
| Performance | Near-native | Some overhead from hypervisor |
| Resource Usage | Lightweight, shares kernel | Heavy, dedicated resources per VM |
| Portability | Runs anywhere with Docker | Requires compatible hypervisor |
| Boot Time | Instant | Minutes per VM |
Because containers share the host operating system kernel, they are far more efficient than VMs. A single host can run dozens or hundreds of containers but only a handful of VMs.
Docker Images and Layers
What is a Docker Image?
A Docker image is a read-only template that contains instructions for creating a container. Images are built in layers, where each layer corresponds to a command in the Dockerfile.
UnionFS & Layered Architecture
Docker uses Union File Systems (UnionFS) such as OverlayFS to combine multiple file system layers into a single coherent view. Each layer is cached and reusable:
- Each instruction in a Dockerfile creates a new layer
- Layers are stacked on top of each other
- If a layer hasn't changed, Docker reuses the cached version
- This makes builds fast and saves disk space
# Each line creates a new layer
FROM node:18-alpine # Layer 1: base image
WORKDIR /app # Layer 2: working directory
COPY package*.json ./ # Layer 3: dependency files
RUN npm install # Layer 4: installed dependencies
COPY . . # Layer 5: application code
CMD ["node", "server.js"] # Layer 6: startup commandDockerfile Instructions
A Dockerfile is a text file with instructions for building a Docker image. Here are the most common instructions:
| Instruction | Purpose | Example |
|---|---|---|
FROM |
Sets the base image | FROM node:20-alpine |
WORKDIR |
Sets working directory | WORKDIR /usr/src/app |
COPY |
Copies files from host | COPY . . |
RUN |
Executes commands during build | RUN npm install |
CMD |
Default command at runtime | CMD ["node", "app.js"] |
EXPOSE |
Documents container port | EXPOSE 3000 |
ENV |
Sets environment variables | ENV NODE_ENV=production |
ARG |
Build-time variables | ARG VERSION=1.0 |
ENTRYPOINT |
Configures container as executable | ENTRYPOINT ["docker-entrypoint.sh"] |
VOLUME |
Creates mount point for external data | VOLUME /data |
Best Practices for Dockerfiles
- Use specific base image tags — prefer
node:20-alpineovernode:latest - Minimize layers — combine related
RUNcommands with&& - Leverage build cache — copy dependency files before source code
- Use multi-stage builds — separate build and runtime dependencies
- Run as non-root — use the
USERinstruction for security
Docker Compose
Docker Compose allows you to define and run multi-container applications using a YAML file (docker-compose.yml). With a single command (docker compose up), you can start all services defined in the file.
Example docker-compose.yml
version: "3.9"
services:
web:
build: .
ports:
- "3000:3000"
depends_on:
- db
environment:
- DATABASE_URL=postgres://user:pass@db:5432/mydb
db:
image: postgres:15
volumes:
- pgdata:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: secret
volumes:
pgdata:Compose is ideal for local development, testing, and staging environments where multiple services (web server, database, cache, queue) must work together.
Docker Hub and Registries
Docker Hub is the default public registry for Docker images. A container registry stores and distributes Docker images:
- Docker Hub — public and private repositories
- GitHub Container Registry (ghcr.io) — integrated with GitHub
- Amazon ECR — AWS container registry
- Google Artifact Registry — GCP container registry
- Azure Container Registry — Azure container registry
Images are referenced by their repository and tag:
docker pull node:20-alpine
docker push yourusername/myapp:latest
Common Docker CLI Commands
| Command | Description |
|---|---|
docker pull <image> |
Download an image from a registry |
docker build -t <tag> . |
Build an image from a Dockerfile |
docker run <image> |
Run a container from an image |
docker ps |
List running containers |
docker ps -a |
List all containers (including stopped) |
docker stop <container> |
Stop a running container |
docker rm <container> |
Remove a container |
docker rmi <image> |
Remove an image |
docker exec -it <container> sh |
Open a shell inside a running container |
docker logs <container> |
View container logs |
docker compose up |
Start services defined in compose file |
docker compose down |
Stop and remove compose services |
docker images |
List all images |
docker system prune |
Remove unused containers, images, and networks |
Development Workflow Benefits
Consistency Across Environments
Docker eliminates "it works on my machine" by ensuring every developer, test server, and production instance runs the exact same environment.
Faster Onboarding
New team members can start contributing with a single docker compose up command instead of following lengthy setup documentation.
Isolation
Each application and its dependencies run in isolated containers, preventing version conflicts between projects on the same machine.
CI/CD Integration
Docker containers are the foundation of modern CI/CD pipelines, allowing teams to build, test, and deploy with confidence.
Microservices Architecture
Docker makes it practical to break monoliths into microservices, each running in its own container with its own dependencies and scaling independently.
LangStop Docker & DevOps Tools
- YAML Formatter — Format your docker-compose.yml files
- YAML Validator — Validate YAML syntax for Docker Compose
- JSON Formatter — Pretty print Docker config JSON files
- YAML to JSON — Convert docker-compose YAML to JSON