Docker Basics

A comprehensive guide to Docker and containerization

What is Docker?

Docker is a platform for developing, shipping, and running applications in containers. Containers allow developers to package an application with all its dependencies into a standardized unit for software development and deployment.

Containerization DevOps Microservices

Core Concepts

Containers

Lightweight, standalone executable packages that include everything needed to run an application:

  • Code
  • Runtime
  • System tools
  • Libraries
  • Settings

Images

Read-only templates used to create containers. Images are:

  • Built from Dockerfiles
  • Stored in registries
  • Versioned with tags
  • Layered architecture

Docker Engine

The core Docker application that:

  • Builds images
  • Runs containers
  • Manages networking
  • Handles storage

Essential Commands

Basic Dockerfile

# Use an official Python runtime as the base image
FROM python:3.9-slim

# Set the working directory
WORKDIR /app

# Copy requirements file
COPY requirements.txt .

# Install dependencies
RUN pip install -r requirements.txt

# Copy application code
COPY . .

# Expose port
EXPOSE 5000

# Run the application
CMD ["python", "app.py"]

Container Lifecycle

Build Image
Create Container
Start Container
Stop Container
Remove Container