-
Notifications
You must be signed in to change notification settings - Fork 257
/
Dockerfile
68 lines (50 loc) · 2.29 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
ARG R_VERSION=latest
FROM rocker/r-ver:${R_VERSION}
LABEL org.opencontainers.image.authors="barret@rstudio.com"
# BEGIN rstudio/plumber layers
# `rm` call removes `apt` cache
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
git-core \
libssl-dev \
libcurl4-gnutls-dev \
curl \
libsodium-dev \
libxml2-dev \
&& rm -rf /var/lib/apt/lists/*
# `rm` call removes install2.r's cache
RUN install2.r --error --skipinstalled --ncpus -1 \
remotes \
&& rm -rf /tmp/downloaded_packages
## Remove this comment to always bust the Docker cache at this step
## https://stackoverflow.com/a/55621942/591574
#ADD https://github.com/rstudio/plumber/commits/ _docker_cache
ARG PLUMBER_REF=main
RUN Rscript -e "remotes::install_github('rstudio/plumber@${PLUMBER_REF}')"
EXPOSE 8000
ENTRYPOINT ["R", "-e", "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)"]
# Copy installed example to default file at ~/plumber.R
ARG ENTRYPOINT_FILE=/usr/local/lib/R/site-library/plumber/plumber/04-mean-sum/plumber.R
RUN cp ${ENTRYPOINT_FILE} ~/plumber.R
CMD ["~/plumber.R"]
# EOF rstudio/plumber layers
# README:
# Usage (adjust the tags/versions according to your preferences):
# build docker file
# docker build --build-arg R_VERSION=4.0.2 -t rstudio/plumber:latest .
# run with defaults
# docker run -it -p 8000:8000 --rm --name plumber rstudio/plumber:latest
# open in browser
# firefox http://localhost:8000/__swagger__/ &
# to run with your own api - mount your plumber.R file into the container like so:
# docker run -it -p 8000:8000 --rm -v ~/R/x86_64-pc-linux-gnu-library/4.0/plumber/plumber/10-welcome/plumber.R:/api/plumber.R:ro --name myapi rstudio/plumber:latest /api/plumber.R
# then browse with
# curl http://localhost:8000/
# Extend the rstudio/plumber:TAG Dockerfile / build your own custom image adding debian packages and your own api:
## ./Dockerfile
# FROM rstudio/plumber:latest
# RUN apt-get update -qq && apt-get install -y \
# [list-your-debian-packages-here]
# # add app files from host's present working dir
# COPY . /api
# # set default startup command to run the app's "plumber.R" file
# CMD ["/api/plumber.R"]