Docker eliminates the "works on my machine" problem by packaging applications with all their dependencies into standardized containers. As of 2025, over 20 million developers use Docker monthly.
Core Concepts
Images are read-only templates containing your app code, runtime, libraries, and system tools. Containers are running instances of images — lightweight, isolated processes sharing the host OS kernel. Unlike VMs, containers start in milliseconds and use minimal RAM.
Your First Dockerfile
FROM php:8.3-fpm-alpine
WORKDIR /var/www/html
RUN apk add --no-cache zip unzip curl \
&& docker-php-ext-install pdo pdo_mysql opcache
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY . .
RUN composer install --no-dev --optimize-autoloader
EXPOSE 9000
CMD ["php-fpm"]Essential Commands
# Build an image
docker build -t myapp:1.0 .
# Run a container
docker run -d -p 8080:9000 --name myapp myapp:1.0
# View running containers
docker ps
# View logs
docker logs -f myapp
# Enter a running container
docker exec -it myapp shVolumes for Persistent Data
Containers are ephemeral — when they stop, data inside is lost. Use volumes to persist databases:
docker volume create mysql_data
docker run -d -v mysql_data:/var/lib/mysql mysql:8.0Multi-Stage Builds
Reduce image size by separating build and runtime stages. A typical Node.js app drops from 1.2GB to under 150MB:
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/htmlMulti-stage builds keep production images lean, secure, and fast to deploy.