Build Docker Image from Alpine with 'later' R-package - r

When I try build an image from the following Dockerfile, it fails. (I am using Portainer, it simply shows "build failed" with no further explanation.)
FROM rhub/r-minimal:4.0.5
RUN apk update
RUN installr -d -t "R-dev file linux-headers libxml2-dev gnutls-dev openssl-dev libsass-dev libx11-dev cairo-dev libxt-dev libuv-dev geos-dev gdal-dev proj-dev sqlite-dev cmark-dev http-parser-dev" \
-a "libxml2 libuv cmark libgit2 openssl cairo libsass libx11 font-xfree86-type1 sqlite proj gdal geos http-parser" later
RUN rm -rf /var/cache/apk/*
RUN addgroup --system app && adduser --system --ingroup app app
I am trying to build an image for shiny/leaflet and this package seems to be responsible for not getting there...
I also tried the r-hub/r-minimal example but it failed too.
I am aware of this discussion but can not act on it.
Interestingly, the following Dockerfile works:
FROM rhub/r-minimal:4.0.5
RUN apk update
RUN installr -d -t "R-dev file linux-headers libsodium-dev" \
-a "libsodium font-xfree86-type1" later
RUN rm -rf /var/cache/apk/*
RUN addgroup --system app && adduser --system --ingroup app app
Any ideas on how to get a small Docker image for shiny/leaflet is very appreciated.

Related

Shiny app does not appear when deployed using Shinyproxy

I'm trying to learn how to deploy a shiny app using Shinyproxy, and I'm using the templated "euler app" (from this repo), but the application does not appear when I navigate to http://localhost:4445. Here's the most similar question I could find, but unfortunately not helpful to my issue: link.
Background
All installations seem fine, and I successfully installed Docker and Java.
The Dockerfile and Docker image work locally, no issues there. The command docker run --rm -p 3838:3838 shiny-euler-app works.
Here is my Dockerfile (copied from the repo):
FROM openanalytics/r-base
MAINTAINER Tobias Verbeke "tobias.verbeke#openanalytics.eu"
# system libraries of general use
RUN apt-get update && apt-get install -y \
sudo \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev \
libxt-dev \
libssl-dev \
libssh2-1-dev \
libssl1.1
# system library dependency for the euler app
RUN apt-get update && apt-get install -y \
libmpfr-dev
# basic shiny functionality
RUN R -e "install.packages(c('shiny', 'rmarkdown'), repos='https://cloud.r-project.org/')"
# install dependencies of the euler app
RUN R -e "install.packages('Rmpfr', repos='https://cloud.r-project.org/')"
# copy the app to the image
RUN mkdir /root/euler
COPY euler /root/euler
COPY Rprofile.site /usr/lib/R/etc/
EXPOSE 3838
CMD ["R", "-e", "shiny::runApp('/root/euler')"]
As well, Shinyproxy works fine with the default openanalytics/shinyproxy-demo Docker image, as you can see:
Problem
The issue I have is when I try and supply a different Shiny app and its accompanying application.yml. Here is the application.yml file I'm using (I've tried to make it as basic as possible, with no authentication, etc):
proxy:
title: Standalone Docker Engine
port: 4445
authentication: none
docker:
url: http://localhost:2375
specs:
- id: euler
display-name: Euler's number
container-cmd: ["R", "-e", "shiny::runApp('/root/euler')"]
container-image: shiny-euler-app
Unfortunately, when I run java -jar shinyproxy-2.4.2.jar (in the directory which contains the shinyproxy-2.4.2.jar file and the application.yml file) I get this blank webpage:
For some reason, I am able to access the Shinyproxy webpage, but the Dockerized Shiny app does not appear.
Would really appreciate any helpful suggestions on where/how I could try and solve this issue. Thanks!

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:
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
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.
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:
which doesn't really line up with any of the distributions in the Shiny Server documentation, thus making the documentation unhelpful.
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?
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"]

shiny app docker container failed to launch in browser

I'm trying to run my shiny app in a docker container.
My app folder structure is like this:
myApp (directory)
-app (directory)
--ui.R
--server.R
--global.R
--style.css
--mydata.xlsx
--mydata2.rds
--functions.R (contains functions I use in app)
-Dockerfile
-shiny-server.conf
-shiny-server.sh
I can get into my directory myApp and run shiny locally by doing runApp('app'). my shiny app runs perfectly.
However, when I try to build the image and run it, it give me error.
docker build -t myshinyapp_obs .
docker run -p 80:80 myshinyapp_obs
The application failed to start.
The application exited during initialization.
The docker image building process seems to be fine.
When run it on docker, I got error.
The interesting thing is when I simply copy any app from shiny gallery and put the ui.R and server.R file under the app folder, it works fine!!!
My question is why my app is not working? given the fact:
my app work perfectly locally
After copying shiny example from gallery into the app folder, the example app works fine.
How can that happen? I cannot figure it out. Spent hours trying to make it work but failed.
Below is my Dockfile:
# Install R version 3.6
FROM r-base:3.6.0
# Install Ubuntu packages
RUN apt-get update && apt-get install -y \
sudo \
gdebi-core \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev/unstable \
libxt-dev \
libssl-dev
# Download and install ShinyServer (latest version)
RUN wget --no-verbose https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && \
VERSION=$(cat version.txt) && \
wget --no-verbose "https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && \
gdebi -n ss-latest.deb && \
rm -f version.txt ss-latest.deb
# Install R packages that are required
# TODO: add further package if you need!
RUN R -e "install.packages(c('devtools','readxl','tidyverse','rlang','shiny','shinythemes', 'DT'), repos='http://cran.rstudio.com/')"
# Copy configuration files into the Docker image
COPY shiny-server.conf /etc/shiny-server/shiny-server.conf
COPY /app /srv/shiny-server/
# Make the ShinyApp available at port 80
EXPOSE 80
# Copy further configuration files into the Docker image
COPY shiny-server.sh /usr/bin/shiny-server.sh
CMD ["/usr/bin/shiny-server.sh"]

Migrating from standard to flexible environment in google app engine

I'm migrating my standard environment app to flexible environment in GAE and facing issues.
app.yaml snippet
runtime: custom
env: flex
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
Dockerfile
FROM gcr.io/google_appengine/python-compat-multicore
RUN apt-get update -y
RUN apt-get install -y python-pip build-essential libssl-dev libffi-dev python-dev libxml2-dev libxslt1-dev xmlsec1
RUN apt-get install -y curl unzip
RUN curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz
RUN mkdir -p /usr/local/gcloud
RUN tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz
RUN /usr/local/gcloud/google-cloud-sdk/install.sh
RUN curl https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.40.zip > /tmp/google_appengine_1.9.40.zip
RUN unzip /tmp/google_appengine_1.9.40.zip -d /usr/local/gae
ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin
ENV PATH $PATH:/usr/local/gae/google_appengine/
COPY . /app
WORKDIR /app
ENV MODULE_YAML_PATH app.yaml
RUN pip install -r requirements.txt
issue while running gcloud app deploy(stack trace)
File "/env/local/lib/python2.7/site-packages/google/appengine/ext/vmruntime/vmconfig.py", line 63, in BuildVmAppengineEnvConfig
escaped_appid = appid.replace(':', '_').replace('.', '_')
AttributeError: 'NoneType' object has no attribute 'replace'
Is there anything which I'm missing in dockerfile? What are the other configuration changes which should be done such that there is not much application level code changes. Is it advidsable to use webapp2 in flexible environment
We're working on a better error message, but this is happening because you're trying to use the python-compat-multicore runtime. That runtime is not supported on env:flex, and has been deprecated. We're asking folks to follow this guide to upgrade to runtime:python:
https://cloud.google.com/appengine/docs/flexible/python/migrating

grunt-cli doesn't work with docker volume mounted, fine without

I set up an angular development environment using the following Dockerfile (don't try to build this unless you're really enthusiastic, it takes an age).
FROM ubuntu:14.04
# build environment
RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "nodejs", "npm", "git"]
RUN ["ln", "-s", "/usr/bin/nodejs", "/usr/bin/node"]
RUN ["npm", "install", "-g", "yo"]
RUN ["npm", "install", "-g", "bower"]
RUN ["npm", "install", "-g", "grunt-cli"]
WORKDIR /home/angular
ADD ./package.json /home/angular/package.json
ADD ./bower.json /home/angular/bower.json
ADD ./dist /home/angular/dist
RUN ["npm", "install"]
RUN ["bower", "install", "--allow-root"]
# sass depedencies
ENV RUBY_MAJOR 2.2
ENV RUBY_VERSION 2.2.2
ENV RUBY_DOWNLOAD_SHA256 5ffc0f317e429e6b29d4a98ac521c3ce65481bfd22a8cf845fa02a7b113d9b44
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN ["apt-get", "install", "-y", "curl"]
RUN apt-get update \
&& apt-get install -y autoconf bison libgdbm-dev ruby \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/ruby \
&& curl -fSL -o ruby.tar.gz "http://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.gz" \
&& echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.gz" | sha256sum -c - \
&& tar -xzf ruby.tar.gz -C /usr/src/ruby --strip-components=1 \
&& rm ruby.tar.gz \
&& cd /usr/src/ruby \
&& autoconf \
&& ./configure --disable-install-doc \
&& make -j"$(nproc)" \
&& make install \
&& apt-get purge -y --auto-remove bison libgdbm-dev ruby \
&& rm -r /usr/src/ruby
# skip installing gem documentation
RUN echo 'gem: --no-rdoc --no-ri' >> "$HOME/.gemrc"
# install things globally, for great justice
ENV GEM_HOME /usr/local/bundle
ENV PATH $GEM_HOME/bin:$PATH
ENV BUNDLER_VERSION 1.10.5
RUN gem install bundler --version "$BUNDLER_VERSION" \
&& bundle config --global path "$GEM_HOME" \
&& bundle config --global bin "$GEM_HOME/bin"
# don't create ".bundle" in all our apps
ENV BUNDLE_APP_CONFIG $GEM_HOME
RUN gem install compass
VOLUME ["/home/me/code/correspondence/client/dist"]
ADD ./ /home/angular
If I run this with:
sudo docker run -it me/angular /bin/bash
I can use grunt build with no problems. Since I haven't attached a volume to dist that build is no use to other containers such as the webserver. But running:
sudo docker run -itv /home/me/code/correspondence/client/dist:/home/angular me/angular /bin/bash
results in the grunt build command no longer being usable in the container:
grunt-cli: The grunt command line interface. (v0.1.13)
Fatal error: Unable to find local grunt.
If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project. For more information about
installing and configuring grunt, please see the Getting Started guide:
http://gruntjs.com/getting-started
The only difference is adding the volume. How does adding the volume result in this different behaviour?
I suppose that's because you have placed some files to /home/angular in image and when you're mounting your volume to the same path (/home/angular), your volume hides original files.
Quote from documentation:
Note: If the path /opt/webapp already exists inside the container’s
image, its contents will be replaced by the contents of /src/webapp on
the host to stay consistent with the expected behavior of mount
Try to mount volume to another directory, /home/angular/dist/client, for instance.

Resources