DevDocsDev Docs

Docker for Developers

Complete guide to Docker including Dockerfile creation, Docker Compose orchestration, and CLI commands for containerized applications

Welcome to the Docker for Developers documentation! This comprehensive guide covers everything from creating Dockerfiles to orchestrating multi-container applications with Docker Compose.

What You'll Learn

This documentation covers:

  • Dockerfile: Building optimized container images with best practices
  • Docker Compose: Orchestrating multi-container applications
  • CLI Commands: Essential Docker commands for daily workflows
  • Networking: Container communication and network configuration
  • Volumes: Data persistence and volume management
  • Security: Best practices for secure container deployments

Docker Architecture

Prerequisites

Before diving in, you should have:

  1. Docker Desktop or Docker Engine installed
  2. Basic command line familiarity
  3. Understanding of Linux fundamentals

Installation

Install Docker from docker.com or use your package manager.

Quick Navigation

Topic Overview

Dockerfile

Master container image creation:

  • Base Images: Choosing the right foundation
  • Instructions: FROM, RUN, COPY, CMD, ENTRYPOINT
  • Multi-stage Builds: Optimizing image size
  • Layer Caching: Speeding up builds
  • Best Practices: Security and optimization

Docker Compose

Learn multi-container orchestration:

  • Services: Defining application components
  • Networks: Container communication
  • Volumes: Data persistence
  • Environment Variables: Configuration management
  • Profiles: Environment-specific setups

CLI Commands

Essential commands for daily workflows:

  • Container Management: run, start, stop, rm
  • Image Management: build, pull, push, tag
  • Inspection: logs, exec, inspect
  • Cleanup: prune, system df

Docker Workflow

Quick Start

Verify Installation

# Check Docker version
docker --version

# Check Docker Compose version
docker compose version

# Verify Docker is running
docker info

Run Your First Container

# Run a simple container
docker run hello-world

# Run an interactive container
docker run -it ubuntu bash

# Run a web server
docker run -d -p 8080:80 nginx

Build Your First Image

# Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
# Build the image
docker build -t my-app .

# Run the container
docker run -d -p 3000:3000 my-app

Container Lifecycle

Key Concepts

Images are read-only templates used to create containers.

# List images
docker images

# Pull an image
docker pull nginx:alpine

# Remove an image
docker rmi nginx:alpine

# Build an image
docker build -t my-app:latest .

Images are built in layers, with each instruction in a Dockerfile creating a new layer.

Containers are runnable instances of images.

# List running containers
docker ps

# List all containers
docker ps -a

# Start a container
docker start container_name

# Stop a container
docker stop container_name

# Remove a container
docker rm container_name

Containers are isolated processes that share the host OS kernel.

Volumes provide persistent storage for containers.

# Create a volume
docker volume create my-data

# List volumes
docker volume ls

# Mount a volume
docker run -v my-data:/app/data my-app

# Bind mount
docker run -v $(pwd):/app my-app

Volumes persist data even when containers are removed.

Networks enable container communication.

# List networks
docker network ls

# Create a network
docker network create my-network

# Connect container to network
docker network connect my-network container_name

# Run container on specific network
docker run --network my-network my-app

Docker provides bridge, host, and overlay network drivers.

Best Practices Summary

Production Considerations

Always follow these best practices when deploying to production.

CategoryBest Practice
ImagesUse specific tags, not latest
SecurityRun as non-root user
SizeUse multi-stage builds
CachingOrder Dockerfile instructions wisely
ComposeUse environment files for secrets
VolumesNamed volumes for persistent data
NetworksCustom networks for isolation
CleanupRegular pruning of unused resources

On this page