rocker-org / rocker-versioned2

Run current & prior versions of R using docker. rocker/r-ver, rocker/rstudio, rocker/shiny, rocker/tidyverse, and so on.
https://rocker-project.org
GNU General Public License v2.0
417 stars 181 forks source link

solve Fatal error: cannot create 'R_TempDir' without mounting local path #854

Closed stephenturner closed 1 month ago

stephenturner commented 2 months ago

Container image name

rocker/shiny-verse:4.4.0

Container image digest

rocker/shiny-verse@sha256:70581cd6ed8968b4c41513231265d5b780f3c4d7d5259389b59b7fedfd34a35b

What operating system related to this question?

macOS

System information

Question

I'm trying to run a modified version of the container image at https://github.com/tbaccata/amica/blob/master/Dockerfile using rocker/shiny-verse.

When I run the image with the default /init CMD, I get the following error in the shiny logs:

*** '/var/log/shiny-server//shiny-server-shiny-20240910-203209-39535.log' has been created ***

*** /var/log/shiny-server//shiny-server-shiny-20240910-203209-39535.log ***
su: ignoring --preserve-environment, it's mutually exclusive with --login
Fatal error: cannot create 'R_TempDir'

Everything I find searching google for this error suggests there isn't enough space in /tmp.

When I add -v /tmp:/tmp to my docker run, the container runs just fine and the app works.

If I don't add this volume mount, I get the error above. I can shell into the running container and make directories and write to /tmp in the running container. But for my use case I can't mount a local path to the /tmp volume. I don't understand why the /tmp in the container can't be ephemeral storage in the container that's used as TMP storage.

Thanks for any advice.

eitsupi commented 2 months ago

I think it is very difficult to say anything as you do not have a reproducible example and do not know what is going on on your computer. Why don't you first go inside that container and see what happens when you try to manually create a file on /tmp?

If you can get it into a general case, you could ask it as a general Docker question at SO etc.

stephenturner commented 2 months ago

Thanks for the quick reply.

When I interactively hop into the container I can write to /tmp when there's no volume mount to tmp. I can do this from R as well.

$ docker run --rm -it -p 3838:3838 stephenturner/amica bash
root@9e5b43bca454:/data# echo 'hello' > /tmp/whatever
root@9e5b43bca454:/data# cat /tmp/whatever
hello
root@9e5b43bca454:/data# Rscript -e 'tf=tempfile(); write.table(iris, tf); head(read.table(tf))'
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa

When I launch the app with /init and try to load the app at http://127.0.0.1:3838/, it fails to start, with errors in the browser:

An error has occurred
The application failed to start.

The application exited during initialization.

And errors in the shiny logs pointing to Fatal error: cannot create 'R_TempDir':

root@9e5b43bca454:/data# /init
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 01_set_env: executing...
skipping /var/run/s6/container_environment/HOME
[cont-init.d] 01_set_env: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.

*** warning - no files are being watched ***
[2024-09-11T07:46:58.944] [INFO] shiny-server - Shiny Server v1.5.23.1020 (Node.js v18.18.2)
[2024-09-11T07:46:58.948] [INFO] shiny-server - Using config file "/etc/shiny-server/shiny-server.conf"
[2024-09-11T07:46:59.029] [WARN] shiny-server - Running as root unnecessarily is a security risk! You could be running more securely as non-root.
[2024-09-11T07:46:59.038] [INFO] shiny-server - Starting listener on http://[::]:3838
[2024-09-11T07:47:04.286] [INFO] shiny-server - created bookmark state directory: /var/lib/shiny-server/bookmarks
[2024-09-11T07:47:04.287] [INFO] shiny-server - created user bookmark state directory: /var/lib/shiny-server/bookmarks/shiny
[2024-09-11T07:47:04.491] [INFO] shiny-server - Error getting worker: Error: The application exited during initialization.

*** '/var/log/shiny-server//shiny-server-shiny-20240911-074704-39769.log' has been created ***

*** /var/log/shiny-server//shiny-server-shiny-20240911-074704-39769.log ***
su: ignoring --preserve-environment, it's mutually exclusive with --login
Fatal error: cannot create 'R_TempDir'

However, when I mount the local /tmp to /tmp on the container, everything works fine, and the app loads.

$ docker run --rm -it -p 3838:3838 -v /tmp:/tmp amica bash
root@aeeb80a68a10:/data# /init

Version info

$ sw_vers
ProductName:        macOS
ProductVersion:     14.3
BuildVersion:       23D56

$ docker --version
Docker version 27.1.1, build 6312585

$ docker run --rm stephenturner/amica Rscript -e 'library(shiny); sessionInfo()'
R version 4.4.0 (2024-04-24)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] shiny_1.9.1

loaded via a namespace (and not attached):
 [1] compiler_4.4.0    magrittr_2.0.3    fastmap_1.2.0     R6_2.5.1
 [5] cli_3.6.2         promises_1.3.0    later_1.3.2       htmltools_0.5.8.1
 [9] Rcpp_1.0.12       digest_0.6.35     xtable_1.8-4      httpuv_1.6.15
[13] lifecycle_1.0.4   mime_0.12         rlang_1.1.4
eitsupi commented 2 months ago

Are you using CPU architecture emulation? Could you reproduce the problem with a more minimal image instead of the one you built? At this point I can't determine if it's a problem with your machine or the image - do you have the same problem on other machines running Linux? (I believe problems often occurs with Docker on macOS)

Anyway I think you need to create a minimal reproducible example.

stephenturner commented 1 month ago

Thanks for the idea about turning off Rosetta emulation. I tried that, didn't work. This does seem to be working on a Linux VM on GCP. I'm not sure I can easily get the example much more minimal than docker run --rm -it -p 3838:3838 stephenturner/amica built using the Dockerfile linked above. Somewhere the app is attempting to write to /tmp and isn't able to if /tmp isn't a volume mount from the host system. At least on MacOS. In any case, I'll close this as it seems to be a MacOS-specific issue. I'll reopen if I can narrow down the app to something truly minimal. Thanks again.