For Docker 1.9.0 and above,
Use volume API
docker volume create --name hello
docker run -d -v hello:/container/path/for/volume container_image my_command
If you create a container with a -v volume_name:/container/fs/pathdocker will automatically create a named volume for you that can:
- Be listed through the docker volume ls
- Be identified through the docker volume inspect volume_name
- Backed up as a normal dir
- Backed up as before through a --volumes-from connection
The new volume api adds a useful command that let you identify dangling volumes:
docker volume ls -f dangling=true
And then remove it through its name:
docker volume rm <volume name>
as @mpugach underlines in the comments you can get rid of all the dangling volumes with a nice one liner:
docker volume rm $(docker volume ls -f dangling=true -q)
# or using 1.13.x
docker volume prune
Hope this answer helps you.