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

Users can't access container environment variables #112

Closed gowerc closed 5 years ago

gowerc commented 5 years ago

I am new to docker so I apologies if this is a basic question with an obvious answer.

I can't see to get container environment variables to be made available to users within rocker rstudio.

Dockerfile:

FROM rocker/tidyverse:3.5.1
ENV CONTAINER=DOCKER_R
CMD ["/init"]

From the command line within the container:

echo $CONTAINER
DOCKER_R

From within Rstudio

> system("echo $CONTAINER")

(that is a blank line i.e. nothing gets returned)

I tried moving the variable declaration to the /etc/profile and a script within /etc/profile.d/ but neither of these seemed to fix the issue.

docker --version
Docker version 18.06.1-ce, build e68fc7a

(am on windows)

cboettig commented 5 years ago

Correct, ENV variables you declare in a root user environment inside the Dockerfile (or as args at build time) are not by default visible to all users. Put them into /etc/environment to make them globally available:

FROM rocker/tidyverse:3.5.1
ENV CONTAINER=DOCKER_R
RUN echo $CONTAINER >> /etc/environment

Or maybe into usr/local/lib/R/etc/Renviron if you prefer.

eddelbuettel commented 5 years ago

Or /etc/R/ depending on which container you use -- the ones using the R package have that convenience softlink for /etc/R -> /usr/local/lib/R/etc which save some typing.

gowerc commented 5 years ago

Hi all,

Thanks for the information. For reasons that I don't understand

ENV CONTAINER=DOCKER_R
RUN echo "CONTAINER=$CONTAINER" >> /etc/environment

Does not work for me (should it ?!), however

ENV CONTAINER=DOCKER_R
RUN echo "CONTAINER=$CONTAINER" >> /usr/local/lib/R/etc/Renviron

does work.

Is there anywhere that defines exactly what the differences between these files and the etc/R directory is ? Also should adding it to /etc/environment be working ?

eddelbuettel commented 5 years ago

You comingle two questions.

The first is about shell init (/etc/environment) versus R init. It depends on what process read which file for startup. There is some fine print hiding somewhere. But if this does not work, skip it.

The second is about /etc/R and there is magic. It is just a symlink on systems that have it.

gowerc commented 5 years ago

Sure, well at least I have it working now, thank you for your help :)