I am currently trying to dockerize an RShiny application I wrote, and I am having issues reading in the .Renviron variable at the beginning of my script. Below is my console output.
❯ docker run --rm -p 6969:6969 r-app
Attaching package: ‘lubridate’
The following objects are masked from ‘package:base’:
date, intersect, setdiff, union
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
✔ ggplot2 3.3.3 ✔ purrr 0.3.4
✔ tibble 3.0.6 ✔ dplyr 1.0.4
✔ tidyr 1.1.2 ✔ forcats 0.5.1
✔ readr 1.4.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ lubridate::as.difftime() masks base::as.difftime()
✖ readr::col_factor() masks scales::col_factor()
✖ lubridate::date() masks base::date()
✖ purrr::discard() masks scales::discard()
✖ dplyr::filter() masks stats::filter()
✖ lubridate::intersect() masks base::intersect()
✖ dplyr::lag() masks stats::lag()
✖ lubridate::setdiff() masks base::setdiff()
✖ lubridate::union() masks base::union()
Warning message:
In readRenviron(".Renviron") :
file '.Renviron' cannot be opened for reading
Error: Failed to connect: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Execution halted
And below is my Dockerfile. The .Renviron file exists in the same folder as my app.R file, so I'm not sure why it's not able to open it.
FROM rocker/verse:latest
# Install Ubuntu packages
RUN apt-get update && apt-get install -y \
sudo \
gdebi-core \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev
# Download and install ShinyServer
RUN wget --no-verbose --no-check-certificate https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-1.5.7.907-amd64.deb && \
gdebi shiny-server-1.5.7.907-amd64.deb
RUN R -e "install.packages('lubridate', repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('RMariaDB', repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('scales', repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('shiny', repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('stringr', repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('tidyverse', repos='http://cran.rstudio.com/')"
# Copy configuration files into the Docker image
#COPY shiny-server.sh /usr/bin/shiny-server.sh
#COPY ttp-internal-reporting.Rproj /srv/shiny-server/
#COPY app.R /srv/shiny-server/
#COPY .Renviron /srv/shiny-server/
COPY . /srv/shiny-server/
# select port
EXPOSE 6969
CMD ["Rscript", "srv/shiny-server/app.R"]
There is really not a lot of documentation or examples out on the internet for reading in an .Renviron file for a dockerized app, and I do not want to eschew using this file because it contains database credentials for getting our data. Any help is greatly appreciated.