简体   繁体   English

Express.js在Docker容器内找不到模块'opencv'

[英]Express.js Cannot find module 'opencv' inside of a docker container

I am trying to install the OpenCV bindings for NODE so that I can use AI with my express server. 我正在尝试为NODE安装OpenCV绑定,以便可以将AI与我的Express服务器一起使用。 I am using the Peter Braden Library - https://github.com/peterbraden/node-opencv . 我正在使用Peter Braden库-https: //github.com/peterbraden/node-opencv

However, I keep getting a repeated issue when spinning up the docker container which states: 但是,在旋转docker容器时,我不断遇到重复的问题,其中指出:

express_1  | Error: Cannot find module 'opencv'
express_1  |     at Function.Module._resolveFilename (module.js:485:15)
express_1  |     at Function.Module._load (module.js:437:25)
express_1  |     at Module.require (module.js:513:17)
express_1  |     at require (internal/module.js:11:18)
express_1  |     at Object.<anonymous> (/myapp/routes/OpenCV.js:3:10)
express_1  |     at Module._compile (module.js:569:30)
express_1  |     at Object.Module._extensions..js (module.js:580:10)
express_1  |     at Module.load (module.js:503:32)
express_1  |     at tryModuleLoad (module.js:466:12)
express_1  |     at Function.Module._load (module.js:458:3)
express_1  |     at Module.require (module.js:513:17)
express_1  |     at require (internal/module.js:11:18)
express_1  |     at Object.<anonymous> (/myapp/app.js:69:16)
express_1  |     at Module._compile (module.js:569:30)
express_1  |     at Object.Module._extensions..js (module.js:580:10)
express_1  |     at Module.load (module.js:503:32)
express_1  | npm info lifecycle backend@0.0.0~start: Failed to exec     start script
express_1  | npm ERR! code ELIFECYCLE
express_1  | npm ERR! errno 1
express_1  | npm ERR! backend@0.0.0 start: `node ./bin/www`
express_1  | npm ERR! Exit status 1
express_1  | npm ERR! 
express_1  | npm ERR! Failed at the backend@0.0.0 start script.
express_1  | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
express_1  | 
express_1  | npm ERR! A complete log of this run can be found in:
express_1  | npm ERR!     /root/.npm/_logs/2017-10-25T15_32_12_258Z-debug.log
maya_express_1 exited with code 1

I have tried accessing the container and using bash within to install open cv but this does not work either. 我尝试访问该容器并在其中使用bash安装打开的cv,但这也不起作用。

I am running on Sierra 10.12.6 我在Sierra 10.12.6上运行

If I delete node_modules and then run - 如果我删除node_modules然后运行-

docker run -v $(pwd):/myapp express-dev:1.0.0 npm install

it throws me a completely different error 引发了一个完全不同的错误

 gyp info spawn args   '-Goutput_dir=.' ]
 /myapp/node_modules/opencv/utils/find-opencv.js:21
                 throw new Error("ERROR: failed to run: pkg-config", opencv, flag);
            ^

 Error: ERROR: failed to run: pkg-config
     at /myapp/node_modules/opencv/utils/find-opencv.js:21:23
     at ChildProcess.exithandler (child_process.js:277:5)
     at emitTwo (events.js:125:13)
     at ChildProcess.emit (events.js:213:7)
     at maybeClose (internal/child_process.js:921:16)
     at Socket.stream.socket.on (internal/child_process.js:348:11)
     at emitOne (events.js:115:13)
     at Socket.emit (events.js:210:7)
     at Pipe._handle.close [as _onclose] (net.js:549:12)
 gyp: Call to 'node utils/find-opencv.js --cflags' returned exit status 1 while in binding.gyp. while trying to load binding.gyp

I have tried relinking opencv and using opencv@2 as well with no luck. 我尝试重新链接opencv并使用opencv @ 2,但也没有运气。

My Dockerfile: 我的Dockerfile:

# Based off: https://hub.docker.com/r/danlynn/ember-cli/
# See ./provisioning/containers for more.

FROM node:8.2.1
MAINTAINER thestartupfactory.tech <hello@thestartupfactory.tech>
ENV WORKDIR=/opt NODE_ENV=production

# express server on 3000
# ember will be compiled and served via express
EXPOSE 3000
# Use /opt for building container
WORKDIR $WORKDIR

# See WORKDIR command at end of file
CMD ["npm", "start"]

# Update the image
# Install ember dev dependencies
# Install ember-cli and express-generator
RUN \
    apt-get update -y && \
    npm install -g bower@1.8.0 &&\
    npm install -g ember-cli@2.14.2 &&\
    npm install -g express-generator@4.15.0

# Import the code
RUN \
    mkdir -p /opt/ember && \
    mkdir -p /opt/express

COPY ./frontend/ /opt/ember/
COPY ./backend/ /opt/express/

# Run npm install
# Compile ember, insert to express && delete ember source
# Cleanup caches
RUN \
    cd /opt/ember && npm install &&\
    ember build --environment production && mv dist/ ../express/ &&\
    cd .. && rm -rf ember &&\
    cd /opt/express && npm install && cd .. &&\
    apt-get clean &&\
    apt-get autoremove --purge

# Move the WORKDIR ready for entrypoint
WORKDIR $WORKDIR/express

Any help would be greatly appreciated! 任何帮助将不胜感激! Thanks in advance 提前致谢

Looks like you did not even set up node-opencv in your docker image. 看起来您甚至没有在docker映像中设置node-opencv。 There is a difference between setting up node-opencv on your local machine and in your docker image. 在本地计算机和docker映像中设置node-opencv之间有区别。 In your Dockerfile you have to include the commands to setup opencv and node-opencv. 在Dockerfile中,您必须包含用于设置opencv和node-opencv的命令。 You can refer to the OpenCV travis.yml if you are unsure how to setup OpenCV in a Linux environment. 如果不确定如何在Linux环境中设置OpenCV,可以参考OpenCV travis.yml。

Alternatively you can have a look at opencv-express . 另外,您可以看看opencv-express It is an example of how to use opencv with nodejs and express. 这是如何将opencv与nodejs和express一起使用的示例。 It uses opencv4nodejs however. 但是,它使用opencv4nodejs。 You can also just pull one of the provided base images, depending on the OpenCV version you want to use and install your node environment with node-opencv on top. 您还可以仅提取提供的基本映像之一,具体取决于要使用的OpenCV版本,并在顶部安装node-opencv的节点环境进行安装。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM