Hosting an R plumber API using docker

1.8k views Asked by At

I work on a windows laptop and want to host an API of mine that I made in R (using plumber package) using docker desktop for windows. The tutorial found here gives an example of running a pre-installed plumber code using this command: docker run --rm -p 8000:8000 rstudio/plumber. This hosts the API that is present in the given location: "C:\Users\sidmh\Documents\R\win-library\4.0\plumber\examples\04-mean-sum\plumber.R" However, I want to host an API present in this location: "C:\Users\sidmh\Documents\Nutri\plumber.R" How can I do this?

1

There are 1 answers

0
cbo On BEST ANSWER

You will need to adapt (from the plumber documentation) the Dockerfile to get your custom my_plumber_api.R script stored in the 'app' folder with something along :

Dockerfile

FROM rstudio/plumber

# list all the needed packages here in the same fashion
RUN R -e "install.packages('broom')"

# to launch your docker container
CMD ["/app/my_plumber_api.R"]

Then you will need to build (and tag for convenience) the docker image before being able to run it with :

$ cd projet_folder
$ docker build -t my_plumber_api .
$ docker run -p 8000:8000 my_plumber_api

You should check the Docker documentation for specifics (choose the exposed port, ...).