【问题标题】:Run NodeJS and R in same Docker container在同一个 Docker 容器中运行 NodeJS 和 R
【发布时间】:2022-01-14 11:10:46
【问题描述】:

我在同一个 docker 容器中运行 NodeJS 应用程序和 R 并安装几个包时遇到问题。 我的 Dockerfile 看起来像这样:

# 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"]

它可以编译,但是当我尝试运行一些 R 脚本时,它会抛出 sfrgeos 未安装的错误。

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

我可以看到,当我运行docker-compose up --build 时,在构建和编译过程中有一些gcc 错误,但我不知道如何访问它们。他们只是在构建过程中临时登录。

编辑:我设法抓住了几个错误:

=> # 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

任何想法如何解决这个问题?

【问题讨论】:

    标签: r node.js docker docker-compose dockerfile


    【解决方案1】:

    对于这些高级软件包,您需要额外的系统库。 将这些添加到单行 RUN 并在最后进行清理(这将减少构建图像的最终大小)

    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/*
    
    

    【讨论】:

    • 谢谢!我添加了其他库,但它仍然给我同样的错误,说没有包 Error in library(sf) : there is no package called 'sf' 。我通过r-integration (npmjs.com/package/r-integration) 在我的节点环境中使用脚本。会不会是个问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    • 2014-09-27
    • 2023-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多