Run NodeJS and R in same Docker container

Published

I am having issues running a NodeJS application and R in the same docker container and installing a couple of packages.
My Dockerfile looks like this:

# Create image based on the official Node 6 image from the dockerhub
FROM node:12.16.3

# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app

# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app

# Copy dependency definitions
COPY package.json /usr/src/app

# Install dependencies
RUN npm install

# Get all the code needed to run the app
COPY . /usr/src/app

RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y curl libcurl4-openssl-dev
RUN apt-get install -y apt-utils

RUN apt-get install -y r-base
RUN apt-get install -y r-base-dev
RUN apt-get install -y libssl-dev

#RUN R -e "install.packages('terra', repos='http://cran.us.r-project.org')"
RUN R -e "install.packages('sf', repos='http://cran.us.r-project.org')"
#RUN R -e "install.packages('rgdal', repos='http://cran.us.r-project.org')"
RUN R -e "install.packages('rgeos', repos='http://cran.us.r-project.org')"
#RUN R -e "install.packages('rstac', repos='http://cran.us.r-project.org')"
#RUN R -e "install.packages('gdalcubes', repos='http://cran.us.r-project.org')"
#RUN R -e "install.packages('raster', repos='http://cran.us.r-project.org')"

# Expose the port the app runs in
EXPOSE 8781

# Serve the app
CMD ["npm", "start"]

It compiles but when I try to run some R script it throws the error that sf and rgeos are not installed.

backend_1   | [R: compile error] Error: Command failed: "/usr/bin/Rscript" -e "source('./R/GetSatelliteImages.R') ; print(generateSatelliteImageFromAOI(bottomLeftX=7.518893145684743,bottomLeftY=51.991643436139015,topRightX=7.65207434323406,topRightY=51.94955306671286,datetime='2022-01-02/2022-01-03',limit=100,desiredBands=c('B03','B04','SCL'),resolution=60,cloudCoverageInPercentage=1))"
backend_1   | Error in library(rgeos) : there is no package called 'rgeos'
backend_1   | Calls: print ... generateSatelliteImageFromAOI -> getBBoxFromAOI -> library
backend_1   | Execution halted
backend_1   | 
backend_1   | aoi: Unexpected error occured
backend_1   | [R: compile error] Error: Command failed: "/usr/bin/Rscript" -e "source('./R/GetSatelliteImages.R') ; print(generateSatelliteImageFromTrainingData(trainingDataPath='./public/uploads/trainingsdaten_koeln.geojson',datetime='2022-01-02/2022-01-03',limit=100,desiredBands=c('B03','B04','SCL'),resolution=60,cloudCoverageInPercentage=1))"
backend_1   | Error in library(sf) : there is no package called 'sf'
backend_1   | Calls: print -> generateSatelliteImageFromTrainingData -> library
backend_1   | Execution halted

I can see that when I run docker-compose up --build, in the building and compiling process there are a few g++ errors but I don’t know how to access them. They only get logged temporarily in the building process.
Any ideas how to fix this?

Source: Docker Questions

Published
Categorised as docker, docker-compose, dockerfile, node.js, r Tagged , , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq