Trouble acessing plumber API in docker

Hello !

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 !

Answer : to have it run with swagger you should modify as bellow.

R/to_run_api_shirin_docker.R

r$run(host = "0.0.0.0", port = 8000, swagger = TRUE)

For those who whant to dig in I adapted the very good blog post of Shirin Glander :slight_smile: https://shirinsplayground.netlify.app/2018/01/plumber/

1 Like

Instead of

CMD ["R", "-e source('R/to_run_api_shirin_docker.R')"]

You could also use

ENTRYPOINT ["R", "-f", "R/to_run_api_shirin_docker.R", "--slave"]

-f : takes input from file

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.