Containers, as opposed to images, store data in writable layers. When a container is erased, the readable layer is removed, leaving the underlying image intact. Docker volumes enable data exchange between containers, maintaining consistency and accessibility across deployments.
When we construct a Docker container, we add a read-write (R/W) layer on top of the image's read-only (R/O) layer. This prepares the container to run the programme by pulling the image, setting the environment variables, configuring the entry point, and so on.
Docker volumes are helpful when you run a database as a container for storing your data.