Home > Software engineering >  Problem building R api with plumber, RPostgreSQL, and docker
Problem building R api with plumber, RPostgreSQL, and docker

Time:06-07

I'm trying to install plumber and RPostgreSQL into my docker image. Here's my dockerFile:

FROM rocker/r-base


RUN R -e "install.packages('plumber')"
RUN R -e "install.packages('RPostgreSQL')"

RUN mkdir -p /code
COPY ./plumber.R /code/plumber.R

CMD Rscript --no-save /code/plumber.R

The only thing my plumber script does is try to reference the RPostgreSQL package:

library('RPostgreSQL') 

When I build, it appears to successfully install both packages, but when my script runs, it complains that RPostgreSQL doesn't exist. I've tried other base images, I've tried many things.

Any help appreciated. Thanks!

CodePudding user response:

You are trying to install RPostgres and then trying to load RPostgreSQL -- these are different packages. Hence the error.

Next, as you are on r-base, the latter is installed more easily as sudo apt install r-cran-rpostgresql (maybe after an intial sudo apt update). While you're at it, you can also install plumber as a pre-made binary (along with its dependencies). So

RUN apt update -qq \
     && apt install --yes --no-install-recommends \
            r-cran-rpostgresql \
            r-cran-plumber

is easier and faster.

  • Related