Writing to mounted volume by Shiny app from inside Docker container: App crashes

My goal: Create docker container with Shiny app that writes a file to a mounted volume.

Replex: As a minimal reproducible example I created: GitHub - vincentvanhees/rshiny_in_docker_test: Report to test using Rshiny in Docker with mounted volume , which is a Shiny app that has a single button to initiate the writing of a tiny text file to the mounted volume. The container only takes a minute to build and installation steps are in the README.

What works: When launched outside the docker container, directly from RStudio, the app works fine and the file is written after the button is clicked.

Issue: When launched via Docker the app with button are visible, but when the button is clicked the app crashes. No log file is stored inside /var/log/shiny-server.

My own investigation so far: I am using Ubunutu 18.04 and managed to replicate the issue in Ubuntu 20.04 with virtual machine. However my colleague is not able to replicate the issue on his OSx. So, the issue may relate to the operating system and/or docker version. I am using the latest docker version 20.10.12, build e91ed57.

Question: Does anyone here have suggestions on how I can resolve this?

The info below is a copy from what you can also find in the repo (see link above):

My Dockerfile:

# get shiny server and R from the rocker project
FROM rocker/shiny

SHELL ["/bin/bash",  "--login", "-c"]

# install R packages required
RUN R -e 'install.packages("remotes", \
RUN R -e 'remotes::install_github("vincentvanhees/rshiny_in_docker_test")'

# Copy code to run the app to the container
RUN mkdir -p /code
COPY /code/app.R /srv/shiny-server/

# Change working directory to equal the location of the mounted volume
WORKDIR /srv/shiny-server/data

# run app
CMD ["/usr/bin/shiny-server"]

I am launching the container with:
docker run --rm -it -v ~/:/srv/shiny-server/data/ -p 3838:3838 -u shiny test-app

Did you check the permissions on the host?

I am root on the host, but I suppose that is not what you mean.
I use -u shiny in my docker command because rocker/shiny has that as its internal user, but also when I use -u root or entirely skip the -u argument the problem persists.

You need to make sure, that the user running the shiny app in the container (in this case shiny) is allowed to write to the volume (or in other words: the directory on the host).

Have you tried to manually (bash) create a file from within the running container?


thanks, I see:

shiny@1e10fe0841da:/srv/shiny-server/data$ whoami
shiny@1e10fe0841da:/srv/shiny-server/data$ touch test.txt
touch: cannot touch 'test.txt': Permission denied

It appears indeed that the shiny user does not have the correct permissions. So, does this mean that I need to manually create a 'shiny' user inside my host and give it access permissions to the volume I intend to mount or can it be via the Dockerfile?

I usually use chown in the DOCKERFILE.

See this or this.

When I follow your second link I conclude that I need to add RUN chown -R 1000:1000 /srv/shiny-server/data to my DOCKERFILE, which I tried without success.

I am not using the VOLUME command they talk about, should I?
Also, I am not doing: RUN useradd -d /home/testuser -m -s /bin/bash testuser, should I? If yes, how do I make this generic rather than specific to testuser?

When I follow your first link:

docker run --rm -it -v ~/dockertest/:/srv/shiny-server/data/ -p 3838:3838 -u `stat -c "%u:%g" ~/dockertest` test-app
[2022-01-28T11:08:59.542] [INFO] shiny-server - Shiny Server v1.5.18.979 (Node.js v12.22.6)
[2022-01-28T11:08:59.544] [INFO] shiny-server - Using config file "/etc/shiny-server/shiny-server.conf"
[2022-01-28T11:08:59.603] [ERROR] shiny-server - Error loading config: The user 'undefined' does not have permissions to run applications as one of the users in 'shiny'. Please restart shiny-server as one of the users in  'shiny'. (/etc/shiny-server/shiny-server.conf:2:1)
[2022-01-28T11:08:59.603] [INFO] shiny-server - Shutting down worker processes

I found another source of guidance:
Sharing files with host machine ยท rocker-org/rocker Wiki (github.com) but none of the suggestion seems to work for me. For example, I tried without success: docker run -d -P -v ~/dockertest/:/srv/shiny-server/data/ -p 3838:3838 -e USERID=$UID test-app

It may help if there was a minimal demo repository to showcase the functionality, a bit like the one I created (see link in my first post above) but then actually functional.

Would you mind sharing a link to your own DOCKERFILE, the one you referred to above?
Maybe that helps me to understand better what you mean. Thanks

Sorry, I can't share my DOCKERFILEs as they are part of a commercial project. However, by now you know what the issue is and that it is not R or shiny related. Accordingly I'd try to bring this up in a forum dealing with docker issues. I don't have the profound docker knowledge to provide you with a bulletproof procedure to track down the issue.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.