Docker for Developers: From Zero to Containerized Applications
Table of Contents
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 sh
Volumes 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.0
Multi-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/html
Multi-stage builds keep production images lean, secure, and fast to deploy.
Related Posts
Docker Compose: Orchestrating Multi-Container Applications
Define and run multi-container applications with Docker Compose — databases, caches, queues, and your app in one command.
Kubernetes Fundamentals: Container Orchestration at Scale
Understand Kubernetes core concepts — Pods, Deployments, Services, and Ingress — to run production workloads at any scale.
CI/CD Pipelines with GitHub Actions: Automate Everything
Build production-grade CI/CD pipelines — run tests, lint code, build Docker images, and deploy automatically on every push.
Comments (0)
No comments yet. Be the first to comment!