Docker: Fundamentals and First Steps

Docker packages applications into containers — isolated processes with their own file system, network and resources.

Image vs. container

An image is the template (immutable), a container is the running instance. Many containers can start from one image.

Important commands

docker build -t my-app .
docker run -d -p 8080:80 my-app
docker ps
docker logs <container>
docker stop <container>

Dockerfile

FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]

Volumes and networks

-v data:/var/lib/mysql makes data persistent; user-defined networks isolate services.

docker-compose

With docker-compose.yml you define multiple services (e.g. web + db) and start everything with docker compose up -d.

See also: Programming.