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!

arvi1000
  • 9,393
  • 2
  • 42
  • 52
  • 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('..')` – alistaire Jan 24 '18 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 – arvi1000 Jan 24 '18 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 – Lorenzo G Jan 24 '18 at 22:45
  • @alistaire if you want to post that as an answer, I will upvote. Thanks – arvi1000 Jan 24 '18 at 22:45
  • @lorenzo -- yup, I extrapolated as much, thanks! – arvi1000 Jan 25 '18 at 04:54

2 Answers2

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.

arvi1000
  • 9,393
  • 2
  • 42
  • 52
  • 2
    Are you able to write to that mounted folder LOOKATMEEE or just read from it? – Harlan Nelson Apr 10 '21 at 12:14
  • 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" – SKyJim Oct 28 '22 at 22:13
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

ROBBAT1
  • 533
  • 4
  • 9