Шпаргалка по Docker и Compose
Жизненный цикл контейнеров, сборка образов, многоэтапные Dockerfile, стеки Compose v2, сети, тома, логи и команды безопасной очистки на Docker 27+.
Принцип работы
Images are immutable layered templates; containers are writable runtime processes from an image; volumes persist state across container replacement; networks wire service DNS.
Набор для выживания
Несколько команд, которые стоит выучить в первую очередь.
42 команды
Run & Inspect Containers
Start containers, map ports, inspect logs, and attach interactive shells.
- Базовый
Start an ephemeral interactive container and delete it on exit
docker run --rm -it <image> <shell>Соберите команду
docker run --rm -it <image> <shell>Значения подставляются точно так, как вы их ввели. Заключите их в кавычки самостоятельно, если в них есть пробелы или спецсимволы.
Когда использовать
Best for throwaway debugging environments without leaving stopped containers behind.
Разбор
- --rm
- Automatically remove container once it exits
- -it
- Interactive stdin (-i) + pseudo-TTY (-t)
Пример
docker run --rm -it alpine:3.20 sh
Images & Multi-Platform Builds
Build, tag, inspect image layers, and manage local registries.
Docker Compose v2
Orchestrate multi-container local stacks cleanly with `docker compose`.
Volumes, Networks & Files
Persist database state, connect containers by service name, and copy files.
Disk Usage & Safe Cleanup
Measure disk consumption and prune unused objects without losing data.