Adding a data volume to your Docker container creates a shared directory between the container and your host file system. Data in volumes is readable and writeable to any number of containers. Data in volumes is designed to persist regardless of a containers life cycle, so deleting a container will not delete or change the data in this volume (by default).
The -v
flag is used to create data volumes with the docker run
and docker create
commands. Any number of volumes can be added to a container (using additional -v
flags in the command). Here is an example recently used for this blog:
docker run -d --name cdh5-hive -v $PWD:/bigdatums -h hadoop-master hswarm/cdh5-hive
The -v $PWD:/bigdatums
portion of the command above creates a volume in the cdh5-hive
container at the /bigdatums
mount point which contains everything in the current working directory ($PWD
).