Reputation: 314
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.
Upvotes: 4
Views: 1092
Reputation: 1881
The environmental variables available in Rstudio are coming from the Renviron
file located at $R_HOME/etc/Renviron
.
According to this thread the environmental variables created when running the docker are not automatically added to this Renviron
.
Therefore you need to add them yourself at the end of the file for them to show in Rstudio.
You can for instance add the following command at the end of your dockerfile that will copy them from a file on your host machine to the docker. (Assuming $R_HOME=/usr/local/lib/R)
COPY my_file /usr/local/lib/R/etc/
RUN cat /usr/local/lib/R/etc/my_file >> /usr/local/lib/R/etc/Renviron
Where the contents of my_file
would be:
MY_VAR=1
Upvotes: 1