docker volume create --name="myAwesomeApp"
Using a named volume makes managing volumes much more human-readable. It is possible to create a named volume using the command specified above, but it's also possible to create a named volume inside of a docker run
command using the -v
or --volume
command line option:
docker run -d --name="myApp-1" -v="myAwesomeApp:/data/app" myApp:1.5.3
Note that creating a named volume in this form is similar to mounting a host file/directory as a volume, except that instead of a valid path, the volume name is specified. Once created, named volumes can be shared with other containers:
docker run -d --name="myApp-2" --volumes-from "myApp-1" myApp:1.5.3
After running the above command, a new container has been created with the name myApp-2
from the myApp:1.5.3
image, which is sharing the myAwesomeApp
named volume with myApp-1
. The myAwesomeApp
named volume is mounted at /data/app
in the myApp-2
container, just as it is mounted at /data/app
in the myApp-1
container.