Docker

Introduction

Docker is a platform that allows you to package applications and their dependencies into lightweight, portable containers. Containers isolate applications from the host system, ensuring consistent behavior across environments.

Key Concepts

Containers: Running instances of applications, isolated but sharing the host OS kernel.

Images: Read-only templates used to create containers. Images can include application code, libraries, and system tools.

Volumes: Persistent storage for containers. Volumes allow data to survive container restarts or deletion.

Networks: Define how containers communicate with each other or the outside world.

Why Use Docker

Consistency: Applications run the same way everywhere.

Isolation: Multiple applications can run on the same host without conflicts.

Portability: Containers can be deployed on any system with Docker.

Efficiency: Lightweight compared to virtual machines.

Docker Basics

Minimal examples to illustrate key concepts:

Run a container:

docker run hello-world

List running containers:

docker ps

Build an image from a Dockerfile:

docker build -t myapp:latest .

Attach a volume to preserve data:

docker run -v mydata:/data ubuntu

Inspect a running container:

docker inspect <container_id>