Day 28/40 - Docker Volume Explained - Docker Bind Mount - Docker Persistent Storage

About this video

### Summary of the Video Content: 1. **Introduction:** - The video is part of the CK 2024 series, specifically video number 28. - It focuses on Docker storage mechanisms, including how storage works behind the scenes and how to make it persistent. - This video serves as a prerequisite for the next video, which will cover Kubernetes storage. 2. **Docker Storage Basics:** - **Layered Architecture:** Docker images are built in layers, with each instruction in the Dockerfile creating a new layer. These layers are read-only. - **Immutable Infrastructure:** Once an image is built, it cannot be changed directly. Any changes require creating a new image, promoting the concept of immutability. - **Delta Changes:** Only the changes (delta) are applied when rebuilding an image, saving time and space by reusing cached layers. 3. **Container Layer (Writable Layer):** - When a container is run, a writable layer (container layer) is added on top of the read-only layers. - Changes made inside the container (e.g., creating files or directories) are stored in this writable layer. - However, data in the writable layer is not persistent—it is lost when the container stops or is removed. 4. **Persistent Storage with Volumes:** - To make data persistent, Docker uses **volumes**. - Volumes are managed by **volume drivers**, which ensure data persists even after the container is stopped or removed. - **Local Volume Driver:** By default, volumes are stored locally on the host machine in the `/var/lib/docker/volumes` directory. - Example: Creating a volume (`data_volume`) and mounting it to a container ensures that data written to the specified directory inside the container is stored persistently on the host. 5. **Storage Drivers vs. Volume Drivers:** - **Storage Drivers:** Responsible for managing the layered architecture of Docker images and writing data to the container layer. - **Volume Drivers:** Ensure data persistence by storing it outside the container lifecycle (e.g., on the host or cloud storage). - Common storage drivers include `Overlay2`, `ZFS`, and `AUFS`. `Overlay2` is widely used for Ubuntu and other Linux distributions. 6. **Mounting Options:** - **Volume Mounting:** Uses the `-v` or `--mount` flag to attach a Docker-managed volume to a container. - **Bind Mounting:** Allows binding a specific directory from the host file system to the container. This is useful for sharing files between the host and container. - Difference: Volume mounting is managed by Docker, while bind mounting directly links a host directory to the container. 7. **Demonstration:** - The presenter demonstrates creating a Docker image, running a container, and interacting with the writable layer. - They show how data in the writable layer is lost when the container is removed but persists when using a volume. - They also demonstrate stopping, restarting, and removing containers while verifying that data in the volume remains intact. 8. **Cloud and Third-Party Storage:** - For cloud environments, Docker supports third-party volume drivers like AWS EBS, GCE Persistent Disk, and Azure File Storage. - These drivers allow storing persistent data in cloud storage instead of locally. 9. **Conclusion:** - The video emphasizes understanding Docker storage concepts, including layered architecture, persistent vs. non-persistent storage, and the role of storage and volume drivers. - These concepts are foundational for understanding Kubernetes storage, which will be covered in the next video. - The presenter encourages viewers to like, comment, and share the video to support the channel. ### Key Takeaways: - Docker uses a layered architecture for images, with each layer being immutable and reusable. - Containers add a writable layer on top of the image layers, but this data is not persistent. - Volumes provide persistent storage, managed by volume drivers, and can be stored locally or in the cloud. - Bind mounts allow linking host directories to containers, offering flexibility for file sharing. - Understanding Docker storage is crucial for working with Kubernetes and other container orchestration tools.


Course: Certified Kubernetes Administrator Full Course For beginners | CKA 2025

This playlist contains the complete CKA series for beginners, based on the latest 2025 curriculum. It includes 40+ videos with hands-on demos, assignments, and exam-based scenarios. We will cover everything from the basics to the Advanced, including fundamental concepts such as Docker, containers, Docker storage and networking, DNS, etc.

View Full Course