add knowledge

This commit is contained in:
Jev Kuznetsov
2026-04-23 12:06:00 +02:00
parent 82985f1976
commit 846eca59d2
10 changed files with 577 additions and 6 deletions
+49
View File
@@ -0,0 +1,49 @@
# Containerization
Package your app and its environment together so it runs identically on every machine — dev, CI, and production.
## Tools
**Docker** is the standard. Everything else (Podman, containerd) is compatible with Docker images.
## Key Concepts
- **Image** — a snapshot of your app + OS + dependencies
- **Container** — a running instance of an image
- **Dockerfile** — the recipe for building an image
- **Local CI pattern** — run your test suite inside a container before pushing; catches environment drift before it reaches remote CI
## Minimal Dockerfile (Python)
```dockerfile
FROM python:3.12-slim
WORKDIR /app
COPY pyproject.toml .
RUN pip install uv && uv pip install --system -e ".[dev]"
COPY . .
CMD ["python", "-m", "mypackage"]
```
## Quickstart
```bash
# build
docker build -t myapp .
# run
docker run --rm myapp
# local CI — run tests inside the container
docker run --rm myapp pytest
# interactive shell for debugging
docker run --rm -it myapp bash
```
## Tips
- Use `.dockerignore` to exclude `__pycache__`, `.git`, `.venv`, `*.pyc`
- Pin the base image tag (`python:3.12-slim`, not `python:latest`)
- Layer ordering matters: copy dependency files before source so the install layer is cached