I would like to mount a local directory when I call docker and have that directory available to be written to without going to drastic extremes of making the user root.
The closest answer I can find is this: Mount local volume accessible to R/RStudio in docker (tidyverse)
or this Permission denied on accessing host directory in Docker
Here, some responders go into detailed explanation: Permission denied on accessing host directory in Docker
That is very close given I am also running the exact same rocker container. That poster seems to be happy, but I wonder if the solution gives the ability to write. Yes I have spent a lot of time reading documentation on this.
In this case is would be nice if the answer to this problem was posted on https://hub.docker.com/r/rocker/rstudio
because given the number of similar question on SO, the solution is not clear to many people.
The closest they get to answering the question is this:
Additional configuration options
Custom user name: -e USER=<CUSTOM_NAME>
Custom user id, group id, UMASK: -e USERID=<UID>, -e GROUPID=<GID>, e UMASK=022
Custom uid/gid etc is usually only needed when sharing a local volume for a user/group whose id does not match the default (1000:1000). Failing to do this could make files change permissions on the linked volume when accessed from RStudio.
Adding additional users: From a root bash shell (see above), the usual debian linux commands can be used to create new users and passwords, e.g.
Here is my solution:
docker run -d -p 8787:8787 -v $(pwd)/myfolder:/home/rstudio/myfolder:z -e PASSWORD=aPogee rocker/rstudio
Here is the error I get when trying to save.
When I try to write a simple file
> getwd()
[1] "/home/rstudio/myfolder"
10 Apr 2021 01:04:52 [rsession-rstudio] ERROR system error 2 (No such file or directory) [path: /home/rstudio/myfolder/temp.R]; OCCURRED AT rstudio::core::Error rstudio::core::FilePath::openForWrite(std::shared_ptr<std::basic_ostream<char> >&, bool) const src/cpp/shared_core/FilePath.cpp:1482; LOGGED FROM: rstudio::core::Error rstudio::core::{anonymous}::openFileForWritingWithRetry(const rstudio::core::FilePath&, bool, int, std::shared_ptr<std::basic_ostream<char> >*) src/cpp/core/FileSerializer.cpp:73