Table of Contents
Basic Docker Concepts
Understand the fundamental concepts of Docker.
Docker uses images, containers, volumes, and networks to isolate and manage applications.
Overview
Docker uses several key concepts to isolate and manage applications. Understanding these concepts is essential for effective Docker usage.
Images
Images are read-only templates that contain everything needed to run an application. They are stored in registries like Docker Hub.
Key points:
- Read-only templates
- Contain application code and dependencies
- Stored in registries (Docker Hub, private registries)
- Built from Dockerfiles
- Can be versioned with tags
Containers
Containers are running instances of images. They are isolated from each other and the host system.
Key points:
- Running instances of images
- Isolated from each other and host
- Can be started, stopped, and removed
- Lightweight compared to virtual machines
- Share host kernel
Volumes
Volumes provide persistent storage for containers. Data in volumes survives container restarts and removals.
Key points:
- Persistent storage for containers
- Data survives container restarts and removals
- Can be named volumes or bind mounts
- Managed by Docker
- Can be shared between containers
Networks
Docker networks allow containers to communicate with each other. By default, containers on the same network can reach each other by service name.
Key points:
- Enable container communication
- Service discovery by name
- Isolated from external networks
- Can be bridge, overlay, or host networks
- Custom networks for better control
Common Docker Commands
```bash docker ps # List running containers docker images # List images docker run image-name # Run a container docker stop container-id # Stop a container docker rm container-id # Remove a container docker exec -it container-id bash # Execute command in container docker logs container-id # View container logs ```
