8

There are a ton of little-upvoted questions about how to address local folders from inside a docker container, but I can't find one that quite matches mine, so here goes another one:

How can I run a docker container, and mount a local folder so that it's accessible by R/RStudio, inside the container?

That sounds kind of like: mounting local home directory in Rstudio docker? and using an approach similar to that, I can start a container and mount a volume:

docker run -d -p 8787:8787 -v $HOME/my_folder:/LOOKATMEEE -e ROOT=TRUE rocker/tidyverse:3.4 

and if I run a bash shell in the container, I can see the folder:

docker exec -it 38b2d6ca427f bash > ls bin dev home lib LOOKATMEEE mnt proc run srv tmp var boot etc init lib64 media opt root sbin sys usr # ^ there is is! 

But if I go connect to RStudio server at localhost:8787, I don't see it in the files pane, nor does it show up when run list.files() in the R console:

enter image description here

I'm sure I'm missing something basic, but if someone can tell me what that is... thank you!

5
  • 1
    I think you just need to set the working directory to the place you copied the folder to, which from the look of it is just setwd('..') Commented Jan 24, 2018 at 22:20
  • Aha, thank you! Yes, it gets mounted as a subdir two levels up, actually -- so setwd('../..') or list.files(../..) would turn it up. What I'm looking for is to have it show up in the default working dir, but now it's clear how to do that Commented Jan 24, 2018 at 22:36
  • 1
    You can mount the drive inside the home directory of user rstudio (the user running RStudio): docker run -d -p 8787:8787 -v $HOME/my_folder:/home/rstudio/LOOKATMEEE -e ROOT=TRUE rocker/tidyverse:3.4 should work Commented Jan 24, 2018 at 22:45
  • @alistaire if you want to post that as an answer, I will upvote. Thanks Commented Jan 24, 2018 at 22:45
  • @lorenzo -- yup, I extrapolated as much, thanks! Commented Jan 25, 2018 at 4:54

2 Answers 2

5

In this circumstance, R and RStudio have a default working directory of /home/rstudio, two levels down from /, where I was telling docker to mount the folder.

After the docker run command in the question, you can go list.files('/') to see the folder.

If you want your folder to show up in the default working directory for R, as I do, then modify docker run like this:

docker run -d -p 8787:8787 -v $HOME/my_folder:/home/rstudio/LOOKATMEEE -e ROOT=TRUE rocker/tidyverse:3.4 

and there it shall be:

enter image description here

Thank you to user alistaire.

Sign up to request clarification or add additional context in comments.

2 Comments

Are you able to write to that mounted folder LOOKATMEEE or just read from it?
Just for completeness: On the left of the ":" goes the location in your laptop and on the right goes the name you want to see in Rstudio. If you want to mount more than one volume then add multiple "-v"
0

This answer is for future generations :)

The concept is a "match" of the resource from the host with the container: :

The command structure should be like this:

docker run -d -e PASSWORD= -p 8787:8787 -v : /home/rstudio/ rocker/rstudio

Check the explanation here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.