Reputation: 71
From the doc docker volume
-v or --volume: Consists of three fields, separated by colon characters (:). The fields must be in the correct order, and the meaning of each field is not immediately obvious.
But I have seen someone using -v flag which only consists of one field:
docker run -v /data ubuntu
What does this option mean? Is this a bind mounts or volume type?
Upvotes: 2
Views: 526
Reputation: 60066
Docker support three type volume and the one above is anonymous volume
anonymous volume
An anonymous volume is useful for when you would rather have Docker handle where the files are stored. It can be difficult, however, to refer to the same volume over time when it is an anonymous volumes. To create an anonymous volume:
docker run -v /path/in/container ...
To find this volume you need to the following step to check the long ID of volumes.
docker inspect container_id
look into Mounts
and then run
docker volume ls | grep volume_id
You will see the volume is created.
host volume
A host volume lives on the Docker host's filesystem and can be accessed from within the container. To create a host volume:
docker run -v /path/on/host:/path/in/container ...
named volume
A named volume is similar to an anonymous volume. Docker manages where on disk the volume is created, but you give it a volume name. To create a named volume:
docker volume create somevolumename
docker run -v name:/path/in/container ...
docker-different-types-of-volumes
Upvotes: 1
Reputation: 752
All three fields are not mandatory "docker run -v /data ubuntu" creates a new volume mounted to /data in a ubuntu container.
Upvotes: 0