6 Using Docker volumes for persistent storage

 

Containers are a perfect runtime for stateless applications. You can meet increased demand by running multiple containers on your cluster, knowing that every container will handle requests in the same way. You can release updates with an automated rolling upgrade, which keeps your app online the whole time.

But not all parts of your app will be stateless. There will be components that use disks to improve performance or for permanent data storage. And you can run those components in Docker containers too.

Storage does add complications, so you need to understand how to Dockerize stateful apps. This chapter walks you through Docker volumes and mounts and shows you how the container filesystem works.

6.1 Why data in containers is not permanent

A Docker container has a filesystem with a single disk drive, and the contents of that drive are populated with the files from the image. You’ve seen that already: when you use the COPY instruction in a Dockerfile, the files and directories you copy into the image are there when you run a container from the image. And you know Docker images are stored as multiple layers, so the container’s disk is actually a virtual filesystem that Docker builds up by merging all the image layers together.

6.2 Running containers with Docker volumes

6.3 Running containers with filesystem mounts

6.4 Knowing the limitations of filesystem mounts

6.5 Understanding how the container filesystem is built

6.6 Lab