Docker Volumes and Stateful Persistence
We can use volumes to save persistent data without relying on the containers. You can think of a volume as a shared folder. In any instance, if you mount the volume to any number of containers, the containers will be able to access the data in the volume. There are two ways to create a volume:
- Create a volume as an independent entity outside any container by using the
docker volume create
subcommand.Creating a volume as an independent object from the container adds flexibility to data management. These types of volumes are also called named volumes because you specify a name for it, rather than leaving the Docker Engine to generate an anonymous numeric one. Named volumes outlive all the containers that are in the system and preserve its data.
Despite these volumes being mounted to containers, the volumes will not be deleted even when all the containers in the system are deleted.
- Create a volume by using the
--mount
or-v
or--volume...