Docker Concepts Explained
Understand the fundamental building blocks of Docker.
Docker Concepts Explained
Before building applications with Docker, it's important to understand the core concepts that make up the Docker ecosystem.
Images
An image is a read-only template used to create containers.
Popular images include:
- nginx
- ubuntu
- node
- redis
- postgres
View local images:
docker images
Containers
A container is a running instance of an image.
Example:
docker run nginx
List running containers:
docker ps
Dockerfile
A Dockerfile contains instructions used to build an image.
Example:
FROM node:20
WORKDIR /app
COPY . .
RUN npm install
CMD ["npm", "start"]
Build an image:
docker build -t my-app .
Registries
Registries store and distribute Docker images.
Popular registries:
- Docker Hub
- GitHub Container Registry
- Amazon ECR
Pull an image:
docker pull nginx
Volumes
Volumes provide persistent storage for containers.
Without volumes:
- Data is deleted when the container is removed.
With volumes:
- Data survives container recreation.
Create a volume:
docker volume create app-data
Networks
Networks allow containers to communicate with one another.
View available networks:
docker network ls
Create a custom network:
docker network create app-network
Putting Everything Together
A typical Docker workflow looks like this:
- Write a Dockerfile.
- Build an image.
- Run a container.
- Store data using volumes.
- Connect services through networks.
- Push images to a registry.
Summary
Docker is built around a few key concepts:
- Images
- Containers
- Dockerfiles
- Registries
- Volumes
- Networks
Understanding these fundamentals makes learning advanced Docker topics much easier.