2

I have some R plumber files working using RStudio, next step is via docker.

The instruction

source('R/to_run_api_shirin_docker.R') 
Starting server to listen on port 8000

don't work and gives the following run :

$ docker run -p 8000:8000 plumber_demo:v4
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> source('R/to_run_api_shirin_docker.R')
Starting server to listen on port 8000

Symptoms :

  • when run in RStudio I should see for logs :
Starting server to listen on port 8000
Running the swagger UI at http://127.0.0.1:8000/__swagger__/
System time: 2020-07-22 16:50:21 
 Request method: GET /__swagger__/ 
 HTTP user agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) enter code hereQtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36 @ 127.0.0.1 
System time: 2020-07-22 16:50:21 
 Request method: GET /swagger.json 
 HTTP user agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36 @ 127.0.0.1 

and there is nothing at

--- scripts bellow ---

Dockerfile

FROM rocker/r-ver:3.6.3
RUN R -e 'install.packages("plumber")'
RUN R -e 'install.packages("randomForest")'
COPY mod_prod_rf.rds data/
COPY plumber_api_shirin_docker.R /R/
COPY to_run_api_shirin_docker.R /R/
CMD ["R", "-e source('R/to_run_api_shirin_docker.R')"]

R/to_run_api_shirin_docker.R

# --- launch API ----
plumb_path <- "R/plumber_api_shirin_docker.R"
r <- plumber::plumb(plumb_path)
r$run(host = "127.0.0.1", port = 8000)

Thanks in advance for any help !

cbo
  • 1,664
  • 1
  • 12
  • 27

1 Answers1

0

I had the same problem when starting with a rocker/r-ver docker repository and trying to add and configure plumber. Resolution for me was to start from a rstudio/plumber repository which has been set up by RStudio folks with plumber and the right network configuration. It allows you to remove some boilerplate and the server responded from the docker container as expected.

Your project might look like this:

FROM rstudio/plumber:v1.0.0
RUN R -e 'install.packages("randomForest")'
COPY mod_prod_rf.rds data/
COPY plumber_api_shirin_docker.R /R/
CMD ["/R/plumber_api_shirin_docker.R"]

Changes from your original:

  • don't need to install plumber since it's in the base repository
  • you don't need the to_run_api_shirin_docker.R file since it does this for you
  • CMD argument is just the file with plumber functions

More info from RStudio on their docker deployment guide here

PS. I didn't figure exactly what the original problem was, but note that in the RStudio plumber Docker configuration they host the API explicitly on 0.0.0.0. Output from running is

> pr <- plumber::plumb(rev(commandArgs())[1]); args <- list(host = '0.0.0.0', port = 8000); if (packageVersion('plumber') >= '1.0.0') { pr$setDocs(TRUE) } else { args$swagger <- TRUE }; do.call(pr$run, args)
Running plumber API at http://0.0.0.0:8000
Running swagger Docs at http://127.0.0.1:8000/__docs__/