- [Instructor] Here's why storage is so important when it comes to Docker containers. You start off with a container. In that container, you run a critical application. It could be a database, or it could even be a number of containers that make up, let's say, a three-tier application. A database with middleware and a front end, all in separate containers. Each of those different containers has specific data that it needs to access.
The applications need their data in order to do their job. But where should that application data be stored? It shouldn't be stored with the container or inside the container. So why not? Well, containers are designed to be ephemeral, or disposable, meaning, you start them up, they're stateless, they do their job, they perform their function. And then, once you power them off, you can easily delete them and they're gone.
When containers are stopped, the data that's inside those containers is no longer accessible. Containers are typically stored on each host. That means that containers running on other hosts could not access the data inside those containers. Also, the container file system wasn't designed for high-performance IO. So what are your options when it comes to storing your data for your critical applications that you're running inside Docker containers? Well, you have a few different options that I'd like to review with you.
First off, you have what they call Docker Volumes. Docker Volumes are the recommended way to persist data, or to store persistent data that needs to live beyond the life of a container. Docker Volume data is stored in var lib docker volumes if you're running Docker on Linux. Another option for data storage when using Docker containers is to use a bind mount.
A bind mount has limited functionality, and you have to use the exact file path on the host. For that reason, and a number of other reasons, Docker Volumes are highly recommended over Docker bind mounts. A third option that you have is called a tempfs mount. Tempfs mounts are stored only in the host memory in Linux, and this is the least recommended option for data storage when using Docker containers.
If we take a look at how this would look visually, you start off with a container. That container is running on top of a file system, and Docker has access to a specific area in that file system. A bind mount directly accesses the file system, whereas a Docker Volume stores its data inside the designated Docker area within the file system. On the other hand, a tempfs mount stores its data inside the memory on the host where the container is running.
It's important to keep these three different options in mind when you consider data storage for Docker containers, with the Docker Volume always being the most highly-recommended option.