Main Content

Share Data with Containers

The file system of a container is isolated from its host system by design. To share data with a container, you can mount folders in the host system to the container using the -v Docker option.

For example, suppose you have a folder on the client machine named MyFolder. This folder contains the subfolder named MySubfolder1, which contains a set of image files. The folder also contains the subfolder MySubfolder2, where you want to save your postprocessed images.

The following option mounts the source folder MyFolder and its subfolders to a target folder in the container, ContainerFolder:

-v /MyMachineName/MyFolder:/ContainerFolder

Add this option when you execute the docker run command.

You can now access and save data within the container in the folder ContainerFolder. Saved data is available in the host in the folder MyFolder. These files persist once the container is stopped. Note that modifying files from within the container overwrites the files on the host.

You can mount as many folders to the container as you need using additional -v options.

Read and Write Cloud Data on AWS

If the host of the container is a remote machine on AWS®, you can upload your local data to Amazon S3™ S3 buckets and then access them from the remote host, for more information see Creating, configuring, and working with Amazon S3 buckets.

If you have data stored in Amazon S3, you can access it directly from MATLAB®. For more information, see Work with Remote Data (MATLAB).

Related Topics