Skip to content

Chapter 5 of 7

Data Persistence and Networking

Containers are designed to be ephemeral, so data written inside them is lost when the container is removed. Docker solves this with volumes, which are persistent storage objects managed by Docker that exist independently of any single container's lifecycle. Volumes can be mounted into multiple containers at once, making it easy to share data between services or to keep state across restarts. You create a named volume with docker volume create volume_name and list existing volumes with docker volume ls.

A common alternative is the bind mount, which maps an arbitrary host directory to a path inside the container. Bind mounts are simple and useful during development because the host filesystem is exposed directly inside the container, but they tie the container to a specific host path and reduce portability. Named volumes are generally preferred for production because Docker handles where they are stored, they work the same way across hosts, and they integrate with the rest of the Docker ecosystem.

Networking follows a similar idea of providing isolation while enabling communication. Each container gets its own network stack, and you choose how containers connect to each other and to the outside world through network drivers such as bridge, host, overlay, or custom networks. The default bridge network lets containers on the same host communicate via IP addresses or automatically assigned names. For more structured setups, docker network create network_name creates a user-defined bridge, while specifying --driver overlay enables multi-host communication used by Swarm clusters.

All chapters
  1. 1Foundations of Containers and Docker
  2. 2Docker Architecture, Installation, and Core CLI
  3. 3Building Images with Dockerfile
  4. 4Running and Managing Containers
  5. 5Data Persistence and Networking
  6. 6Docker Compose and Orchestration with Swarm
  7. 7Security and Troubleshooting

Drill it

Reading is not remembering. These come from the Docker And Containers deck:

Q

What is a container in computing?

A container is a lightweight, standalone, executable package that includes everything needed to run a piece of software, such as code, runtime, libraries, and d...

Q

What is containerization?

Containerization is a virtualization method that packages an application and its dependencies into a container, enabling consistent deployment across different...

Q

What is Docker?

Docker is an open-source platform that automates the deployment, scaling, and management of applications inside containers using containerization technology.

Q

What is the difference between a container and a virtual machine?

Containers share the host OS kernel and are lightweight, starting in seconds, while virtual machines include a full guest OS, making them heavier and slower to...