Steven
Steven

Reputation: 3292

Application logs to stdout with Shiny Server and Docker

I have a Docker container running a shiny app (Dockerfile here).

Shiny server logs are output to stdout and application logs are written to /var/log/shiny-server. I'm deploying this container to AWS Fargate and logging applications only display stdout which makes debugging an application when deployed challenging. I'd like to write the application logs to stdout.

I've tried a number of potential solutions:

  1. I've tried the solution provided here, but have had no luck.. I added the exec xtail /var/log/shiny-server/ to my shiny-server.sh as the last line in the file. App logs are not written to stdout

  2. I noticed that writing application logs to stdout is now the default behavior in rocker/shiny, but as I'm using rocker/verse:3.6.2 (upgraded from 3.6.0 today) along with RUN export ADD=shiny, I don't think this is standard behavior for the rocker/verse:3.6.2 container with Shiny add-on. As a result, I don't get the default behavior out of the box.

  3. This issue on github suggests an alternative method of forcing application logging to stdout by way of an environment variable SHINY_LOG_STDERR=1 set at runtime but I'm not Linux-savvy enough to know where that env variable needs to be set to be effective. I found this documentation from Shiny Server v1.5.13 which gave suggestions in which file to set the environment variable depending on Linux distro; however, the output from my container when I run cat /etc/os-release is:

enter image description here

which doesn't really line up with any of the distributions in the Shiny Server documentation, thus making the documentation unhelpful.

  1. I tried adding adding the environment variable from the github issue above in the docker run command, i.e.,

    docker run --rm -e SHINY_LOG_STDERR=1 -p 3838:3838 [my image]
    

as well as

    docker run --rm -e APPLICATION_LOGS_TO_STDOUT=true -p 3838:3838 [my image]

and am still not getting the logs to stdout.

I must be missing something here. Can someone help me identify how to successfully get application logs to stdout successfully?

Upvotes: 3

Views: 1650

Answers (1)

bathyscapher
bathyscapher

Reputation: 2309

You can add the line ENV SHINY_LOG_STDERR=1 to your Dockerfile (at least, this works with rocker/shiny, not sure about rocker/verse), such as with your Dockerfile:

FROM rocker/verse:3.6.2

## Add shiny capabilities to container
RUN export ADD=shiny && bash /etc/cont-init.d/add

## Install curl and xtail
RUN apt-get update && apt-get install -y \
    curl \
    xtail

## Add pip3 and other Python packages
RUN sudo apt-get update -y && apt-get install -y python3-pip
RUN pip3 install boto3

## Add R packages
RUN R -e "install.packages(c('shiny', 'tidyverse', 'tidyselect', 'knitr', 'rmarkdown', 'jsonlite', 'odbc', 'dbplyr', 'RMySQL', 'DBI', 'pander', 'sciplot', 'lubridate', 'zoo', 'stringr', 'stringi', 'openxlsx', 'promises', 'future', 'scales', 'ggplot2', 'zip', 'Cairo', 'tinytex', 'reticulate'), repos = 'https://cran.rstudio.com/')"

## Update and install 
RUN tlmgr update --self --all
RUN tlmgr install ms
RUN tlmgr install beamer
RUN tlmgr install pgf

#Copy app dir and theme dirs to their respective locations
COPY iarr /srv/shiny-server/iarr
COPY iarr/reports/interim_annual_report/theme/SwCustom /opt/TinyTeX/texmf-dist/tex/latex/beamer/
  
#Force texlive to find my custom beamer theme
RUN texhash

EXPOSE 3838

## Add shiny-server information
COPY shiny-server.sh /usr/bin/shiny-server.sh
COPY shiny-customized.config /etc/shiny-server/shiny-server.conf

## Add dos2unix to eliminate Win-style line-endings and run
RUN apt-get update -y && apt-get install -y dos2unix
RUN dos2unix /usr/bin/shiny-server.sh && apt-get --purge remove -y dos2unix && rm -rf /var/lib/apt/lists/*

# Enable Logging from stdout
ENV SHINY_LOG_STDERR=1

RUN ["chmod", "+x", "/usr/bin/shiny-server.sh"]

CMD ["/usr/bin/shiny-server.sh"]

Upvotes: 1

Related Questions