Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker with renv using rocker/rstudio #446

Closed
gclarkjr5 opened this issue Jun 3, 2020 · 6 comments
Closed

Docker with renv using rocker/rstudio #446

gclarkjr5 opened this issue Jun 3, 2020 · 6 comments

Comments

@gclarkjr5
Copy link

Hi, I was following the best practices for docker with renv from here. I am not sure what I'm doing wrong but it does not seem that I am able to use the rocker/rstudio image in order to use this best practice for running containers. Here is some supporting information:

  • Docker version 19.03.8, build afacb8b
  • Dockerfile for building an image using renv
FROM rocker/rstudio:3.6.3-ubuntu18.04
RUN apt-get upgrade -y && \
apt-get update -y && \
apt-get install -y tzdata
RUN R -e 'install.packages("remotes")'
RUN R -e "remotes::install_github('rstudio/[email protected]')"
  • Docker run command
docker run -d --rm -it --name renv `
-e ROOT=TRUE `
-e DISABLE_AUTH=TRUE `
-e RENV_PATHS_CACHE=/renv/cache `
-p 8787:8787 `
-v C:\Users\other\docker\renv\cache:/renv/cache `
renv:latest

Some issues I tried to work through with no luck

  1. The environment variable RENV_PATHS_CACHE does not pass through to Rstudio
  • In a shell outside of RStudio I am able to run printenv and view the env var, but using Sys.getenv() in Rstudio console the variable does not get picked up. Additionally, if I use the Terminal within Rstudio and run printenv I am unable to see the variable as rstudio user or as root.
  • Manually executing Sys.setenv(RENV_PATHS_CACHE = /renv/cache) has worked, but again, its manual
  1. I'm unable to run renv::restore() as a post-command for the run command above
  • I think this is because of how the base image of rocker/rstudio is designed
  • I was able to begin running post-commands once I added ENTRYPOINT ['R'] as the last command to Dockerfile, but then I have to manually run /init which kickstarts Rstudio

Thanks for your help.

@kevinushey
Copy link
Collaborator

I suspect this is just due to how RStudio Server is launched within Docker containers. I'm not aware of a better fix than just setting RENV_PATHS_CACHE manually. (Maybe you could set it in ~/.Renviron, so it's visible to all new R sessions?)

I'm unable to run renv::restore() as a post-command for the run command above

What do you see when you try to call renv::restore()?

@gclarkjr5
Copy link
Author

What do you see when you try to call renv::restore()?

Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"renv::restore()\": executable file not found in $PATH": unknown.

or even if i try kicking off R to run renv::restore() as a sub command, i.e calling R -e "renv::restore()" instead, i get...
Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"R -e renv::restore()\": executable file not found in $PATH": unknown

I believe it has to do with the CMD ["/init"] as the last line to the Dockerfile for the image.

Currently, my workaround is to run this:

docker run -d --rm -it
-e ROOT=TRUE
-e DISABLE_AUTH=TRUE
-e RENV_PATHS_CACHE=/renv/cache
-p 8787:8787
-v C:\Users\other\docker\renv\cache:/renv/cache
-v C:\Users\other\docker\myproject:/home/rstudio/myproject
renv:latest

As you can see I've added an extra volume, and at the location locally, i have an Rscript containing this:

Sys.setenv(RENV_PATHS_CACHE = '/renv/cache')
setwd("~/myproject")
renv::restore(prompt = FALSE)

once I'm in Rstudio, i just run this and I'm good.

A bit manual, but it works in the meantime i guess.

@KasperSkytte
Copy link

Having the same problem. It's related to this issue rocker-org/rocker#376.

I solved it by also setting RENV_PATHS_CACHE in /usr/local/lib/R/etc/Renviron when building the container, for example adding the line echo "RENV_PATHS_CACHE=/usr/local/lib/R/renv-cache/" >> /usr/local/lib/R/etc/Renviron to the Dockerfile and then making sure the folder is mounted when starting the container.

@KasperSkytte
Copy link

KasperSkytte commented Jun 10, 2021

I made a script to generate a Dockerfile and run here https://gist.github.com/KasperSkytte/270ceb8bc19af7f3bd24c8f9f08f259a. Added a few extra system packages I needed for some R packages, fx Cairo, XML

@KasperSkytte
Copy link

I guess it would be nice to set RENV_PATHS_SOURCE as well?

@hadley
Copy link
Member

hadley commented Apr 28, 2023

Tracking docker recommendation improvements in #599

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants