-
Notifications
You must be signed in to change notification settings - Fork 180
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
R in rocker/r-ver does not respect the container timezone setting. #151
Comments
@eitsupi Yes, it's related to rocker-org/rocker-versioned#89 plus the fact that RStudio doesn't inherit environmental variables from system, only from Renviron. To solve rocker-org/rocker-versioned#89 we need TZ in the system Renviron when RStudio starts. RStudio's choice not to respect system environmental variables is a constant nuisance for rocker users and a source of innumerable issues in these threads, but it's still not clear to me what the most consistent strategy would be. In your second two examples above, it you switched from r-ver to the RStudio interface and ran the same script, can you predict what you would get for TZ in each case? Which one is what you would expect? (current images will give the same TZ either way, the older 3.6.3 will give you a different TZ. Yes, we could restore the old behavior by insisting that env vars needed by RStudio are only run when RStudio is launched. The natural way to do this I think would be in one of the setup scripts run by However, I'm not convinced that it's preferable for RStudio-based containers to have different behavior when a user is running in RStudio interface vs running Rscript. If a user builds and tests a script in rstudio using, say, For consistency across rocker and Rscript, I think users are better off getting used to patterns which pass all env vars needed to R by using an appropriate |
😿 |
@cboettig Thank you for answering in detail. I understood the need to write However, it remains a question whether it is good to have this behavior on My suggestion is to remove this process from #!/bin/bash
set -e
if grep -q "TZ=" ${R_HOME}/etc/Renviron; then
sed -i -e /^TZ=/d ${R_HOME}/etc/Renviron
echo "TZ=${TZ}" >> ${R_HOME}/etc/Renviron
else
echo "TZ=${TZ}" >> ${R_HOME}/etc/Renviron
fi
exec "$@" FROM rocker/rstudio:4.0.5
COPY scripts/entrypoint.sh /rocker_scripts/entrypoint.sh
RUN chmod +x /rocker_scripts/entrypoint.sh
ENTRYPOINT ["/rocker_scripts/entrypoint.sh"]
CMD ["/init"] This image (which I have tagged rstudio-test) rewrites $ docker run --rm -it -e TZ=Asia/Tokyo rstudio-test Rscript -e "Sys.time()"
[1] "2021-04-23 20:17:52 JST" $ docker run --rm -it -e TZ=Asia/Tokyo -p 8787:8787 rstudio-test What do you think of this approach? |
By the way, the reason why I raised this issue this time was because I was asked how to set timezone in a docker container by the Japanese R community yesterday. |
Thanks @eitsupi , I really appreciate your example and the chance to discuss this issue in detail. It's a common friction point and working through this with you helps me think about it more clearly myself as well. Having a custom That's just not true of the other approaches:
When a user asks how to set TZ, I really think "use Renviron" is the most natural answer. It is the standard "R" way of setting environmental variables -- a user doesn't need to know that they are even in docker or to have any control over the docker runtime arguments to set it. The Renviron conventions give greater control to which user or project does or does not inherit the env var. It provides better persistence and portability by declaring these details in config file instead of dynamically at run time, and avoids the issues discussed above. |
@cboettig Thank you for explaining your thoughts to me.
Given the project's emphasis on reproducibility, I thought that the fixed Since I also use Docker for other programming languages (e.g. Python), I found the method of using $ docker run --rm -it --env-file .env python On the other hand, I had a hard time running a script that is supposed to read OS environment variables without using Docker (when passing it to another person who is not using Docker). However, users who use R outside of RStudio may expect the OS environment variables to be read. Also, it would be easier for users to find their way to the configuration on their own if there is a description of
It would be easy to write all the environment variables with the $ env >> ${R_HOME}/etc/Renviron It may be welcome to use a user-set environment variable (e.g. $SINGLE_USER_MODE?) to allow the above process to be controlled by For example, Docker reads the proxy configuration written in |
I bounced upon this topic because I use the images in germany. As far as I understood the discussion a flexible solution for two sides is needed:
In my opinion the easiest way to solve this problem would be to not hard code the value of the TZ variable into the Renviron file. It would be better to write Because the Env-Var is set int he Dockerfile the expression Hope that this can help :-) Edited: Due to the fact the variable expansion is not possible in |
@Pit-Storm Wow, that sounds great. Does this actually work? If I create a local .Renviron with:
and I do:
I still see |
I tried it too, but it doesn't seem to work in RStudio sessions because the user (rstudio by default) doesn't exist when In other words
I think these two changes will make it work, but for the second one, I did not know how to set the OS environment variable for rstudio user. |
At first: The variable expansion has to work, because if you look at ${R_HOME}/etc/Renviron itself there are variables used on the right hand side of the equal sign. I think there must be another reason why this is not working. As I Use the Dockerfile:
and do Even if you start the container with For me it looks like that Rstudio and even R itself is not picking up the Renviron.site and for a strange reason is not expanding the Additionally R and RStudio is not processing Renviron.site when you write Could it have something todo with the install mechanism? Or do you modify some mechanism for the R startup in other scripts? I am not really shure how to debug that 🙈 |
So, i have some more investigations and hints that we have to check. There must be something wrong with the startup process because the rsession of RStudio is not picking up ANY env var in any file. Even the one you set to I really don't get it, but I am not as deep inside the scripts in I am really not getting it... |
Thanks folks! I think we want to edit: https://github.com/rocker-org/rocker-versioned2/blob/master/scripts/install_R.sh#L144 to use single quotes and echo to
Still not entirely convinced that RStudio will evaluate system env vars when parsing the Renviron file, even though R obviously supports that since it uses that notation in the |
The standard reference for that is, I think, our wiki entry in the main repo: https://github.com/rocker-org/rocker/wiki/How-to-contribute -- our repos are sadly a little scattered across the org making things a little harder to find at times. |
#186 has solved this problem in and out of RStudio. Thanks for the great work @Pit-Storm ! $ docker run --rm -it -e TZ=Asia/Tokyo rocker/rstudio:4.1.0 Rscript -e "Sys.time()"
[1] "2021-06-24 19:38:48 JST"
$ docker run --rm -it -e TZ=Asia/Tokyo -e PASSWORD=foobar -p 8787:8787 rocker/rstudio:4.1.0 in RStudio Note that if we run rocker-versioned2/scripts/userconf.sh Lines 29 to 38 in 9cbff13
|
Images build from this repository ignore the OS environment variable
TZ
.That behavior is differently from other rocker images.
For example, since I am in Japan, I sometimes set Japan time.
This is due to the following line added by 6e988b3
rocker-versioned2/scripts/install_R.sh
Line 144 in 391713d
Why is it set like this?
Is it related to this issue? rocker-org/rocker-versioned#89
I don't know the need to write
TZ
toRenviron
file, but how about writingTZ
toRenviron
when the container is started by setting ENTRYPOINT?The text was updated successfully, but these errors were encountered: