Skip to content

Instantly share code, notes, and snippets.

@mskyttner
Last active May 11, 2020 19:03
Show Gist options
  • Save mskyttner/71948117bbadc16be3cec5f64f18a839 to your computer and use it in GitHub Desktop.
Save mskyttner/71948117bbadc16be3cec5f64f18a839 to your computer and use it in GitHub Desktop.
Dockerfile for rstudio/plumber on r-ver:3.6.1
FROM rocker/r-ver:3.6.1
# this is the trestletech/plumber layers, now on a versioned R base
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
git-core \
libssl-dev \
libcurl4-gnutls-dev \
curl \
libsodium-dev \
libxml2-dev
RUN install2.r plumber
EXPOSE 8000
ENTRYPOINT ["R", "-e", "pr <- plumber::plumb(rev(commandArgs())[1]); pr$run(host='0.0.0.0', port=8000, swagger=TRUE)"]
CMD ["/usr/local/lib/R/site-library/plumber/examples/04-mean-sum/plumber.R"]
# EOF trestletech/plumber layers
# README:
# Usage (adjust the tags/versions according to your preferences):
# build with "docker build -t rstudio/plumber:v0.4.6 -t rstudio/plumber:latest ."
# run with defaults "docker run -p 8000:8000 --rm --name plumber rstudio/plumber:v0.4.6"
# browse with "firefox http://localhost:8000/__swagger__/ &"
# remark: the Swagger docs for the POST (sum) method returns HTTP 500 (params a, b not there in annotations?)
# the request when clicking "Execute" from Swagger docs is curl -X POST "http://localhost:8000/sum" -H "accept: application/json"
# this returns "HTTP 500: Internal Server Error"
# the error log from the R console says: <simpleError in (function (a, b) { as.numeric(a) + as.numeric(b)})(): argument "a" is missing, with no default>
# to run with your own api - mount your plumber.R file into the container like so: "docker run -p 8000:8000 --rm -v ~/R/x86_64-pc-linux-gnu-library/3.6/plumber/examples/10-welcome/plumber.R:/api/plumber.R:ro --name myapi rstudio/plumber:v0.4.6 /api/plumber.R"
# then browse with "curl http://localhost:8000/"
# Extend the rstudio/plumber:v0.4.6 Dockerfile / build your own custom image adding debian packages and your own api:
#FROM rstudio/plumber:v0.4.6
# RUN apt-get update -qq && apt-get install -y \
# [list-your-debian-packages-here]
#COPY . /api # add app files from host's present working dir
#CMD ["/api/plumber.R"] # set default startup command to run the app's "plumber.R" file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment