Package your applications with all dependencies into portable containers
Imagine shipping containers - they're standardized boxes that can hold anything and work on any ship, truck, or train. Docker containers work the same way for software! Package your app with everything it needs (code, libraries, dependencies) into a container that runs identically everywhere - your laptop, test server, or production cloud.
"It works on my machine!" - Every developer's nightmare. Your app works locally but breaks in production because of different OS versions, missing libraries, or configuration differences. Docker eliminates this by packaging everything together!
Consistency
Same environment everywhere - dev, test, production
Isolation
Each container is isolated - no conflicts
Portability
Run anywhere - laptop, cloud, on-premises
Efficiency
Lightweight, starts in seconds, uses less resources
Blueprint for containers. Like a recipe - contains instructions to create a container. Immutable and can be shared via Docker Hub.
Running instance of an image. Like a cake made from a recipe. Lightweight, isolated, and disposable.
Text file with instructions to build an image. Defines base image, copies files, installs dependencies, sets commands.
Public registry for Docker images. Like GitHub for containers. Find official images for Node.js, Python, databases, etc.
# Pull an image from Docker Hub
docker pull nginx
# Run a container
docker run -d -p 80:80 nginx
# List running containers
docker ps
# Stop a container
docker stop container_id
# Build image from Dockerfile
docker build -t myapp:1.0 .
# View logs
docker logs container_id
A Dockerfile is your container's recipe. Write it well, and you'll have efficient, secure containers!
# Example Dockerfile for Node.js app
FROM node:18-alpine
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy application code
COPY . .
# Expose port
EXPOSE 3000
# Start application
CMD ["npm", "start"]
Docker Compose lets you define and run multi-container applications. Instead of running multiple docker commands, define everything in a YAML file and start it all with one command!
# docker-compose.yml
version: '3.8'
services:
web:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgres://db:5432
depends_on:
- db
db:
image: postgres:15
environment:
- POSTGRES_PASSWORD=secret
volumes:
- db-data:/var/lib/postgresql/data
volumes:
db-data:
# Start all services
docker-compose up -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f
Awesome! You can now containerize applications with Docker. Next, we'll learn Kubernetes - the industry standard for orchestrating containers at scale. Get ready to manage hundreds of containers!