rocker-org / rocker-versioned

Run current & prior versions of R using docker
https://hub.docker.com/r/rocker/r-ver
GNU General Public License v2.0
297 stars 169 forks source link

"Unable to connect to service" when specifying volume #220

Closed ColinConwell closed 4 years ago

ColinConwell commented 4 years ago

I'm having an issue wherein when I specify volume using the option -v $(pwd):/home/rstudio, I subsequently receive an error "unable to connect to service" after logging in.

This is true for both rocker/rstudio and rocker/tidyverse. I'm imagining this might be some sort of permissions error?

Many thanks for any assistance.

(Full docker calls below; the first works perfectly, the second fails):

docker run -d -p 8787:8787 -e PASSWORD=yourpasswordhere rocker/tidyverse
docker run -d -p 8787:8787 -v $(pwd):/home/rstudio -e PASSWORD=yourpasswordhere rocker/tidyverse
eddelbuettel commented 4 years ago

Could be related to session state file being in $HOME which you altered by mounting the outer directory. Can you try

docker run -d -p 8787:8787 -v $(pwd):/work -e PASSWORD=yourpasswordhere rocker/tidyverse

(or any other value instead of /work -- but make sure not to clobber your home directory).

ColinConwell commented 4 years ago

This seems to have solved the problem!

(My files no longer populating the home directory did perplex me for a moment, but all in all, I think it's only a small inconvenience.)

Thanks very much for the extremely rapid and helpful response!

ColinConwell commented 4 years ago

One minor issue with this solution that I did not realize at the time. It seems that specifying an alternate directory when mounting volumes denies you the permission to write. This is a problem if you're editing an .R file in that directory. Is there a clear workaround for this?

eddelbuettel commented 4 years ago

Yes. You can use -u $(id -u):$(id -g) to pass your (outer) user and group id into the container. Then you "look like the same user" and should be able to write (and not leave traces as the root user).

cboettig commented 4 years ago

@ColinConwell I think you will find it easiest to map a volume into a subdirectory of your home directory, e.g.

docker run -d -p 8787:8787 -v $(pwd):/home/rstudio/work -e PASSWORD=yourpasswordhere rocker/tidyverse

For most users, the UID on their host is 1000, which is the same as the UID of the rstudio user. The rstudio user of course has permissions inside the container to access things inside it's home dir but not outside. More details are provided at https://www.rocker-project.org/use/shared_volumes/ and https://www.rocker-project.org/use/managing_users/

ColinConwell commented 4 years ago

Thanks again for the wonderfully rapid responses. I have different issues with both of these solutions; for @cboettig's solution, I still do not have permission to edit in the work subdirectory.

For @eddelbuettel's solution, the following command seems to execute in Docker, but I am then no longer able to connect via localhost:

docker run -d -p 8787:8787 -u $(id -u):$(id -g) -v $(pwd):/home/rstudio/work -e PASSWORD=yourpasswordhere rocker/tidyverse

Am I inserting the additional argument incorrectly?

noamross commented 4 years ago

If your local user is not 1000, you'll want to pass your user ID as the RStudio user, not the container user, which runs the supervisor processes. To do so you, want to pass your user and group IDs as environment variables rather than the -u argument. The envronment variables are used by the user config script.

docker run -d -p 8787:8787 -e USERID=$(id -u) -e GROUPID=$(id -g) -v $(pwd):/home/rstudio/work -e PASSWORD=yourpasswordhere rocker/tidyverse
ColinConwell commented 4 years ago

@noamross This seems to have worked! Thanks again.