Managing Data for Containers
The file system management of a container.
We'll cover the following
In the last lesson, we looked at how to commit images to the Docker Hub and access it anywhere. Whenever you create a container from an image, it creates a new container without any data except the image data. We created the date-project image, which is a very small image. It has only one project file which we created in the container file system. If the container is removed before committing the changes, we will lose the data. So, it is always good practice to separate your data’s file system from the container’s file system.
Whenever a container is created, a file system is also created with it, which is a default Linux filesystem. Although Docker shares the OS’s kernel, there is a separation between file systems.
Most times, you need to access the host files in the container for faster access to data and while coding as well, because you cannot code, build, and then check your code.
Docker’s bind mount and volumes can be used in such cases. Let’s check them out one by one.
Commands used in this lesson
- docker volume --help: to get the volume help
- docker volume create: to create a new volume
- docker inspect volume: to inspect the created volume
- docker run -v: to mount a volume
Get hands-on with 1400+ tech skills courses.