Add a Shared Directory (Data Volume) to your Docker Container

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:

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).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">