Docker (notes by Atul & Gautam) Intro Docker Architecture Docker Engine: Docker Image: Containers: Docker Registry: Volumes Networking in docker Docker Networking Basics Docker networking enables containers to communicate with each other, the host machine, and external networks while maintaining isolation. Each container runs in its own network namespace, which includes separate IP addresses, routing tables, and interfaces, preventing conflicts with the host or other containers. Default Bridge Network Docker creates a default bridge network called "docker0" upon installation, automatically connecting new containers to it unless specified otherwise. Containers on this network can communicate using IP addresses but not by name, and they access the internet via port mapping from container ports to host ports. User-Defined Networks Create custom networks with docker network create -d bridge my-net to allow containers to resolve each other by name and IP within the same network. This isolates groups of containers, such as frontend and backend services, improving security and organization. Network Types Key Commands Use docker network ls to list networks, docker run --network=my-net to attach a container at startup, or docker network connect my-net container-name for running containers. Containers can join multiple networks for flexible communication across segments. Port Mapping Port mapping in Docker connects a port on your host machine (like your computer) to a port inside a running container, allowing external access to services inside the container. Containers run in isolated network spaces, so without mapping, you can't reach apps like a web server from outside. Docker uses the -p flag with docker run to create this bridge via Network Address Translation (NAT) Basic Syntax Use docker run -p host_port:container_port image_name to map ports. Layers in docker Docker layers are read-only snapshots of filesystem changes created by each instruction in a Dockerfile, stacked together to form a complete image efficiently How Layers Form Each Dockerfile command like RUN, COPY, or ADD creates a new layer capturing only the differences (additions, deletions, or modifications) from the previous state. Layers are immutable once built, enabling Docker to cache and reuse them across images for faster builds. For example, starting from a base image like alpine:latest, a RUN command to install Node.js adds just those changed files as a new layer on top. Union Filesystem Docker uses a union filesystem to stack layers, merging them into a single unified view without copying files between them. When running a container, a temporary read-write layer sits on top, allowing runtime changes that vanish on stop. This design saves storage since shared base layers (e.g., from popular images) are stored once. Extras Commands