Docker đóng gói app + dependencies vào container để chạy nhất quán ở mọi môi trường — containers nhẹ hơn VMs vì share host OS kernel; docker-compose thiết yếu cho local dev stack.
- Docker tạo isolated containers chứa app và dependencies.
- Containers vs VMs: VMs virtualize hardware (heavyweight, có OS riêng, boot minutes); containers share host OS kernel (lightweight, start milliseconds, MB vs GB).
- Layered filesystem (Union FS): Docker image là stack of read-only layers, container thêm writable layer trên cùng — layers được cache và shared giữa images, kéo image nhanh khi layers đã có.
- Copy-on-write: khi container modify file từ image layer, Docker copy file lên writable layer trước khi modify.
- Networking: Bridge network (default, containers communicate qua virtual network); Host network (container dùng host network stack trực tiếp, performance tốt hơn); Overlay network (multi-host, dùng trong Docker Swarm/K8s).
- Volumes: bind mounts (link host directory vào container cho dev mode); named volumes (Docker-managed storage, persist data cho database); tmpfs mounts (in-memory, không persist). docker-compose: define multi-container apps với YAML — services, networks, volumes; docker-compose up để start toàn bộ stack; essential cho local development với database + app + cache.
- Production: Docker + Kubernetes (K8s) cho orchestration, auto-scaling, self-healing; Docker + ECS/Cloud Run cho managed container services.
Docker packages an app and its dependencies into a container for consistent execution anywhere — containers are lighter than VMs because they share the host OS kernel; docker-compose is essential for local dev stacks.
- Docker creates isolated containers that hold the app and its dependencies.
- Containers vs VMs: VMs virtualize hardware (heavyweight, have their own OS, boot in minutes); containers share the host OS kernel (lightweight, start in milliseconds, MB vs GB).
- Layered filesystem (Union FS): a Docker image is a stack of read-only layers, with the container adding a writable layer on top — layers are cached and shared between images, making image pulls faster when layers are already present.
- Copy-on-write: when a container modifies a file from an image layer, Docker copies the file to the writable layer before modifying it.
- Networking: Bridge network (default, containers communicate via a virtual network); Host network (container uses the host network stack directly, better performance); Overlay network (multi-host, used in Docker Swarm/K8s).
- Volumes: bind mounts (link a host directory into the container for dev mode); named volumes (Docker-managed storage, persists data for databases); tmpfs mounts (in-memory, not persisted). docker-compose: define multi-container apps with YAML — services, networks, volumes; docker-compose up to start the entire stack; essential for local development with database + app + cache.
- Production: Docker + Kubernetes (K8s) for orchestration, auto-scaling, self-healing; Docker + ECS/Cloud Run for managed container services.