Skip to main content

Docker

Docker is a platform that uses OS-level virtualization to deliver software in packages called containers. Unlike LXC which aims to emulate a full OS, Docker focuses on packaging a single application and all its dependencies into a portable image.

Key Concepts

  • Image: A read-only template containing the application code, libraries, and environment variables needed to run it. Defined by a Dockerfile.
  • Container: A running instance of an image. It is ephemeral; if deleted, all data inside is lost unless persisted to a volume.
  • Volume: A mechanism to persist data generated by and used by Docker containers, storing it on the host filesystem.
  • Docker Hub: A public registry where you can find pre-built images for almost any software (e.g., Nginx, MySQL, Node.js).

Why Developers Love Docker

  • "It works on my machine": Docker eliminates the inconsistency between development, testing, and production environments. If the container runs on your laptop, it will run exactly the same way on a server.
  • Microservices: Docker is perfect for splitting monolithic applications into small, independently deployable services.

Docker Compose

docker-compose is a tool for defining and running multi-container Docker applications. You configure your application's services, networks, and volumes in a single docker-compose.yml file.

version: '3'
services:
web:
image: nginx:latest
ports:
- "80:80"
db:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: secretpassword

Running docker-compose up -d will start both services and network them together automatically.