Run NodeJS and R in same Docker container
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 gcc
errors but I don't know how to access them. They only get logged temporarily in the building process.
Edit: I have managed to grab a couple of errors:
=> # gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I../inst/include/ -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lyssWw/r-base-3.3.3=. -fstack-p
=> # rotector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c handle-xy.c -o handle-xy.o
=> # gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -I../inst/include/ -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lyssWw/r-base-3.3.3=. -fstack-p
=> # rotector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c identity-filter.c -o identity-filter.o
Any ideas how to fix this?
You'll need additional system libraries for those high level packages. Adding those to a single line RUN with cleaning at the end (that will reduce the final size of the built image)
RUN apt-get update && apt-get install -y \
build-essential curl libcurl4-openssl-dev apt-utils \
r-base r-base-dev libssl-dev \
libudunits2-dev libproj-dev libgdal-dev \
&& rm -rf /var/lib/apt/lists/*