Using Rstudio with Docker compose and passing environment variables to rstudio user

rstudio
docker

#1

I am using docker-compose to create a rstudio service which will be integrated with other services such a db. I am trying to pass some environment variables from the docker-compose.yml file to rstudio. I need these variables in the docker-compose file as they will be changing for each customer. I cannot include them in the Dockerfile and also I cannot copy a .Rprofile file to the docker image.

version: '2.4'
services:
  rstudio:
    environment:
      - USER=rstudio
      - PASSWORD=qwerty
      - MY_VAR=1
    image: "rocker/verse:latest"
    ports:
     - 8787:8787

I want to access MY_VAR from the R environment using the rstudio user.


#2

Is this for the open-source version of RStudio? Environment variables can be accessed from within an R session with Sys.getenv(), so I think any environment variables set here would be accessible within your R sessions as well.