/usr/bin/shiny-server.sh: permission denied when running an R shiny docker on Ubuntu

Viewed 1257

I built a basic R shiny app and wanted to dockerize it on an Ubuntu 18.04 VM.

I followed this blog.

and got the following situation:

R app

app.R

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

   # Application title
   titlePanel("Old Faithful Geyser Data"),

   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)
      ),

      # Show a plot of the generated distribution
      mainPanel(
         plotOutput("distPlot")
      )
   )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2] 
      bins <- seq(min(x), max(x), length.out = input$bins + 1)

      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
}

# Run the application 
shinyApp(ui = ui, server = server)

Dockerfile

# Install R version 3.4
FROM r-base:3.4.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

# Add shiny user
RUN groupadd  shiny \
&& useradd --gid shiny --shell /bin/bash --create-home shiny

# 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('shiny'), 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

# allow permission
RUN sudo chown -R shiny:shiny /srv/shiny-server
#RUN chown shiny:shiny /var/lib/shiny-server

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

shiny-server.conf

# Define the user we should use when spawning R Shiny processes
run_as shiny;

# Define a top-level server which will listen on a port
server {
  # Instruct this server to listen on port 80. The app at dokku-alt need expose PORT 80, or 500 e etc. See the docs
  listen 80;

  # Define the location available at the base URL
  location / {

    # Run this location in 'site_dir' mode, which hosts the entire directory
    # tree at '/srv/shiny-server'
    site_dir /srv/shiny-server;

    # Define where we should put the log files for this location
    log_dir /var/log/shiny-server;

    # Should we list the contents of a (non-Shiny-App) directory when the user 
    # visits the corresponding URL?
    directory_index on;
  }
}

shiny-server.sh

#!/bin/sh

# Make sure the directory for individual app logs exists
mkdir -p /var/log/shiny-server
chown shiny.shiny /var/log/shiny-server

exec shiny-server >> /var/log/shiny-server.log 2>&1

The directory structure is

 - app/app.R
 - Dockerfile
 - shiny-server.sh
 - shiny-server.conf

I use the docker

Docker version 18.09.9, build 1752eb3

and build it using

sudo docker build -t test .

but when running it I get

 sudo docker run test 


docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"/usr/bin/shiny-server.sh\": permission denied": unknown.
ERRO[0001] error waiting for container: context canceled 

I looked through the various forums mentioning this issue and tried changing permissions. I am quite puzzled as it seemed to me that this case was a basic example.

==== Edition after comment ====

I have changed the ownership and the permission of the .sh file

sudo  chown shiny:shiny shiny-server.sh 
 sudo chmod u+ shiny-server.sh 

rebuilt the image

 sudo docker build -t test .

reran it

 sudo docker run test 

but then it does nothing, no error or message of any type, just going to the next line.

0 Answers
Related