I am running a containerized app using nodejs. I understand that I can add node_modules
folder to my .dockerignore
file and have the container install the dependencies itself. However, I have a slightly different usecase.
The bcrypt
error is coming from a local node module I created that was installed in the containerized application using npm install --save ./path/to/my/module
. The local module has a dependency on bcrypt
.
I don't know how to ensure the bcrypt in this module is only installed in the container and not my machine.
Here are some codes from the containerized app
package.json
{
"name": "utme",
"version": "1.0.0",
"description": "UTME App",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"prestart": "npm run build",
"start": "node ./dist/index.js",
"watch": "nodemon -L --exec \"npm run start\" --watch src --ext ts"
},
"repository": {
"type": "git",
"url": ""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"exam-app-core": "file:../../libs/exam-app-core", // local node module dependency that has a dependency on bcrypt
"firebase-admin": "^10.0.2"
},
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/mocha": "^8.2.3",
"@types/node": "^16.11.10",
"@types/sinon": "^10.0.6",
"chai": "^4.3.4",
"chai-http": "^4.3.0",
"cors": "^2.8.5",
"mocha": "^9.1.1",
"morgan": "^1.10.0",
"nodemon": "^2.0.15",
"sinon": "^12.0.1",
"tslint": "^6.1.3",
"typescript": "^4.4.3"
}
}
Dockerfile
FROM node:14-slim
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH /home/node/.npm-global/bin:$PATH
RUN npm i npm@latest mocha@latest -g
WORKDIR /usr/src/app/utme
COPY package.json ./
RUN npm install
COPY . ./
CMD [ "npm", "run", "watch" ]
docker-compose.yml
services:
api:
build:
context: .
dockerfile: Dockerfile
env_file:
- .env.docker
ports:
- "8001:8001"
healthcheck:
disable: true
volumes:
- .:/usr/src/app/utme
- ../../libs/exam-app-core:/usr/src/libs/exam-app-core
- /usr/src/app/utme/node_modules
networks:
- database-net
networks:
database-net:
external: true
name: services_net