Reputation: 3161
I am new to docker and trying to containerise a node app my team have built. Unfortunately, it doesnt seem to build happy.js, a dependency clearly stated in my package.json file. Here is a copy of my 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" ]
The issue is in the backend folder. Here is a copy of the package.json file copied to this folder:
{
"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"
}
}
Unfortunately, I keep getting this error:
backend_1 | > [email protected] 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! [email protected] middleware: `node ./middleware/server.js`
backend_1 | npm ERR! Exit status 1
backend_1 | npm ERR!
backend_1 | npm ERR! Failed at the [email protected] 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
I would be deeply appreciative of any pointers on this
Upvotes: 2
Views: 2648
Reputation: 5357
Your docker file runs npm i hapi -g
, so you install hapi globally on the container, but at no point I see you run npm i
on your workdir. So I guess your application will not be able to locate any local dependency in node_modules
.
I suggest you try adding RUN npm i
in your docker file, right after the line WORKDIR /usr/src/app/backend
.
Upvotes: 3