Skip to content

Sharing files with host machine

Ronald E. Oribio R edited this page Aug 22, 2017 · 2 revisions

This page gives instructions for sharing files/volumes/directories/folders between the docker container and the host machine.

This extract has been taken verbatim from rocker's wiki page.

Mac

The ability to share volumes with Mac hosts is built into Docker >= 1.3. Just link any volume (under /Users/) as you would on Linux:

docker run -v /Users/bob/myapp/src:/src [...]

Still need to test if this requires any special handling of permissions.

Windows

boot2docker provides two current workarounds for sharing directories on Windows, though more native sharing might follow. The official instructions are here but are more complicated than our preferred method of using the -v flag, which you can do like so:

docker run -d -p 8787:8787 -v /c/Users/foobar:/home/rstudio/foobar rocker/rstudio

In this case, /c/Users/foobar corresponds to an existing folder on your computer at C:/Users/foobar, and foobar can be anything. You can now connect to RStudio at http://192.168.59.103:8787 and log in with rstudio/rstusio. With this -v method you can read and write files both ways between Windows and RStudio.

The above approach may not always work, as described in this bug report. The workaround is to either use a double slash or $(pwd):

docker run -d -p 8787:8787 -v //c/Users/foobar:/home/rstudio/foobar rocker/rstudio

or

docker run -d -p 8787:8787 -v /$(pwd):/home/rstudio/foobar rocker/rstudio

Linux

As docker runs natively on Linux, you can always link any volume to the container with the -v or --volume flag, as described in the docker documentation. Note that this overwrites anything on the container that already exists in the target location, and will create the necessary directories if they do not already exist. We recommend running as a non-root user and linking to a subdirectory in that user's home directory as shown below.

Clone this wiki locally