簡體   English   中英

Docker無法從package.json文件安裝依賴項

[英]Docker fails to install dependency from package.json file

我是docker的新手,並試圖收集我的團隊建立的節點應用程序。 不幸的是,它似乎沒有構建happy.js,這是我的package.json文件中明確說明的依賴項。 這是我的DockerFile的副本:

FROM node:8-alpine

WORKDIR /usr/src/app

ENV UV_THREADPOOL_SIZE 64

COPY cdp-contracts/ ./rpc
COPY cdp-platform/  ./backend

RUN rm -rf backend/node_modules
RUN rm -rf rpc/node_modules

RUN apk add --no-cache --virtual .gyp \
    autoconf \
    automake \
    g++ \
    libpng-dev \
    libtool \
    make \
    nasm \
    python \
    git \
  && npm i -g wait-on concurrently truffle npm@latest \
  # && concurrently 'cd rpc;  npm init -y ; npm install --save-exact openzeppelin-solidity; npm init -y ; npm i npm@latest -g ' \
  # && concurrently 'cd backend; npm init -y ; npm i npm@latest -g ; npm i hapi -g; npm rebuild bcrypt --build-from-source' \
  && concurrently 'cd rpc;  npm init -y ; npm install --save-exact openzeppelin-solidity; npm init -y ; npm i npm@latest -g ' \
  && concurrently 'cd backend; npm init -y ; npm i npm@latest -g ; npm i hapi -g; npm rebuild bcrypt --build-from-source' \
  && apk del .gyp

WORKDIR /usr/src/app/rpc

RUN truffle compile --all

WORKDIR /usr/src/app/backend

RUN mkdir -p build/
RUN ln -sf ../../rpc/build/contracts build/contracts

WORKDIR /usr/src/app/backend

EXPOSE 3001

CMD [ "npm", "run", "middleware" ]

問題出在后端文件夾中。 這是復制到此文件夾的package.json文件的副本:

{
    "name": "cdp-platform",
    "version": "0.1.0",
    "description": "the main platform for CDP",
    "main": "server.js",
    "private": true,
    "scripts": {
        "test": "echo ok",
        "space{0}": "--- Services ------------------------------------------------",
        "middleware": "node ./middleware/server.js",
        "middleware:debug": "node --nolazy --inspect-brk=9229 ./middleware/server.js"
    },
    "repository": {},
    "keywords": [],
    "author": "",
    "license": "",
    "dependencies": {
        "agentkeepalive": "3.1.0",
        "async": "2.5.0",
        "axios": "0.18.0",
        "bcrypt": "2.0.1",
        "bignum": "0.12.5",
        "bluebird": "3.5.0",
        "boom": "6.0.0",
        "csv": "3.1.0",
        "csv-parse": "2.5.0",
        "documentdb": "1.14.4",
        "good": "7.1.0",
        "good-console": "6.4.0",
        "good-squeeze": "5.0.2",
        "greenlock": "2.1.12",
        "greenlock-cli": "2.2.6",
        "hapi": "16.1.0",
        "hapi-auth-jwt2": "7.2.4",
        "hapi-authorization": "3.0.3",
        "hapi-swagger": "7.9.1",
        "http-duplex": "0.0.2",
        "inert": "4.2.1",
        "is-stream": "1.1.0",
        "isemail": "3.0.0",
        "joi": "13.0.0",
        "jsonwebtoken": "8.1.0",
        "lodash": "4.17.10",
        "moment": "2.22.1",
        "mongodb": "3.0.10",
        "pm2": "2.6.1",
        "request": "2.80.0",
        "scramjet": "4.15.3",
        "semver": "5.3.0",
        "through": "^2.3.8",
        "through2": "^2.0.3",
        "toobusy-js": "^0.5.1",
        "uuid": "^3.0.1",
        "vision": "^4.1.1",
        "winston": "^2.3.1",
        "xss": "^0.3.3"
    },
    "devDependencies": {
        "babel-eslint": "^8.0.1",
        "chai": "^4.1.2",
        "eslint": "^4.9.0",
        "istanbul": "^0.4.5",
        "mocha": "^5.1.1",
        "mockery": "^2.0.0",
        "nock": "^9.0.9",
        "sinon": "^5.0.7"
    }
}

不幸的是,我一直收到這個錯誤:

backend_1   | > cdp-platform@0.1.0 middleware /usr/src/app/backend
backend_1   | > node ./middleware/server.js
backend_1   |
backend_1   | module.js:550
backend_1   |     throw err;
backend_1   |     ^
backend_1   |
backend_1   | Error: Cannot find module 'hapi'
backend_1   |     at Function.Module._resolveFilename (module.js:548:15)
backend_1   |     at Function.Module._load (module.js:475:25)
backend_1   |     at Module.require (module.js:597:17)
backend_1   |     at require (internal/module.js:11:18)
backend_1   |     at Object.<anonymous> (/usr/src/app/backend/middleware/server.js:2:14)
backend_1   |     at Module._compile (module.js:653:30)
backend_1   |     at Object.Module._extensions..js (module.js:664:10)
backend_1   |     at Module.load (module.js:566:32)
backend_1   |     at tryModuleLoad (module.js:506:12)
backend_1   |     at Function.Module._load (module.js:498:3)
backend_1   | npm ERR! code ELIFECYCLE
backend_1   | npm ERR! errno 1
backend_1   | npm ERR! cdp-platform@0.1.0 middleware: `node ./middleware/server.js`
backend_1   | npm ERR! Exit status 1
backend_1   | npm ERR!
backend_1   | npm ERR! Failed at the cdp-platform@0.1.0 middleware script.
backend_1   | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
backend_1   | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
backend_1   |
backend_1   | npm ERR! A complete log of this run can be found in:
backend_1   | npm ERR!     /root/.npm/_logs/2018-12-04T07_48_39_145Z-debug.log

我會非常感謝有關這方面的任何指示

您的docker文件運行npm i hapi -g ,因此您在容器上全局安裝hapi,但是在任何時候我都看不到您在workdir上運行npm i 所以我猜你的應用程序將無法在node_modules找到任何本地依賴node_modules

我建議你嘗試在你的docker文件中添加RUN npm i ,就在WORKDIR /usr/src/app/backend

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM