Using Volumes with Containers
Explore how to create and manage Docker volumes for persistent data storage within containers. Learn to mount volumes, write data, and retain it even after container removal. Understand how volumes decouple data lifecycle from containers and how to reuse volumes across multiple containers effectively.
Creating a container with a volume
Run the following command to create a new standalone container called voltainer that mounts a volume called bizvol.
$ docker run -it --name voltainer \--mount source=bizvol,target=/vol \alpine
The command specified the --mount flag, telling Docker to mount a volume called bizvol into the container at /vol. The command completed successfully even though you didn’t have a volume called bizvol. This raises an important point:
If you specify a volume that already exists, Docker will use it.
If you specify a volume that does not exist, ...