Docker
Docker is a platform used to package and run applications inside containers.
Containers provide isolated environments while sharing the operating system kernel of the host machine.
Docker Images
A Docker image is a read-only template containing an application and its dependencies.
Images are normally created using a Dockerfile.
Example:
FROM python:3.11 WORKDIR /app COPY . . RUN pip install -r requirements.txt CMD ["python", "app.py"]
Containers
A container is a running instance of an image.
Containers can be started using:
docker run
Running containers can be displayed using:
docker ps
Logs can be viewed using:
docker logs CONTAINER_NAME
Volumes
Containers should not normally store persistent application data inside their writable container layer.
Docker volumes provide persistent storage that can survive container replacement.
Networking
Docker provides virtual networks that allow containers to communicate with each other.
Containers connected to the same Docker network can communicate using container or service names.
Docker Compose
Docker Compose allows multiple related services to be described in a YAML configuration file.
For example, an application can define a web API, PostgreSQL database and Redis service in one Compose configuration.