简体   繁体   中英

Add shiny server with ADD=Shiny with rocker verse image

Documentation for rocker/rstudio docker container .

I am able to get up and running in rstudio using Docker with the following set up in a directory:

Dockerfile:

FROM rocker/tidyverse:latest

docker-compose:

version: "3.5"
services:
  ide-rstudio:
    build:
      context: .
    ports:
      - 8787:8787
    environment:
      ROOT: "TRUE"
      PASSWORD: test

Now, if I enter this dir in the terminal and type: docker-compose build followed by docker-compose up -d and then navigate to localhost:8787 I see the rstudio login screen. So far so good.

I would like to add shiny to the same container per the documentation (as opposed to using a separate shiny image).

On the documentation I link to at the top it says:

Add shiny server on start up with e ADD=shiny

docker run -d -p 3838:3838 -p 8787:8787 -e ADD=shiny -e PASSWORD=yourpasswordhere rocker/rstudio

shiny server is now running on localhost:3838 and RStudio on localhost:8787.

Since I'm using docker-compose I updated my docker-compose file to this:

version: "3.5"
services:
  ide-rstudio:
    build:
      context: .
    ports:
      - 8787:8787
      - 3838:3838
    environment:
      ROOT: "TRUE"
      ADD: "shiny"
      PASSWORD: test

Now, when I go to the terminal like before and type: docker-compose build followed by docker-compose up -d I again see the rstudio login page at localhost:8787. However, if I go to localhost:3838, I see Firefox' 'connection was reset' page. It looks like nothing is there.

How can I add shiny to my container per the instructions?

It seems the image is missing shiny installer. If you run the same compose file without -d and using rocker/rstudio:3.2.0 image you will see in logs that shiny is installing. It failed to install for me (there was a problem with missing file /usr/local/lib/R/site-library/littler/examples/install2.r ) but I found the script which installs the thing. For some reason the script does not exist in rocker/tidyverse:latest (I have no idea why, you'd better ask the maintainer) and ADD=shiny has no effect.

I managed to get things working by injecting that script into rocker/tidyverse:latest and here is how you can do it. Save the following as a file named add :

#!/usr/bin/with-contenv bash

ADD=${ADD:=none}

## A script to add shiny to an rstudio-based rocker image.

if [ "$ADD" == "shiny" ]; then
  echo "Adding shiny server to container..."
  apt-get update && apt-get -y install \
    gdebi-core \
    libxt-dev && \
    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 && \
    install2.r -e --skipinstalled shiny rmarkdown && \
    cp -R /usr/local/lib/R/site-library/shiny/examples/* /srv/shiny-server/ && \
    rm -rf /var/lib/apt/lists/* && \
    mkdir -p /var/log/shiny-server && \
    chown shiny.shiny /var/log/shiny-server && \
    mkdir -p /etc/services.d/shiny-server && \
    cd /etc/services.d/shiny-server && \
    echo '#!/bin/bash' > run && echo 'exec shiny-server > /var/log/shiny-server.log' >> run && \
    chmod +x run && \
    adduser rstudio shiny && \
    cd /
fi

if [ $"$ADD" == "none" ]; then
       echo "Nothing additional to add"
fi

Then either add the following to your Dockefile :

COPY add /etc/cont-init.d/add
RUN chmod +x /etc/cont-init.d/add

or apply execution permission locally and mount it during runtime. To do this run the following locally:

chmod +x add

and add this to docker-compose.yml :

services:
  ide-rstudio:
    volumes:   # this line and below
    - ./add:/etc/cont-init.d/add

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM