Reputation: 21
I am a docker beginner and trying to dockerize simple projects as part of my learning journey..
I am trying to dockerize a NestJS project, but the docker-compose
up command fails.
My Dockerfile and docker-compose.* files look as below. I have tried various changes to Dockerfile and docker-compose files but with no luck.. Can some spot the issue or something that I am missing.
Dockerfile
FROM node:12.10
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm build
docker-compose.yml
version: '3'
services:
app:
build: .
ports:
- '8081:8081'
docker-compose.dev.yml
version: '3'
services:
app:
command: npm start
volumes:
- .:/usr/src/app
environment:
- NODE_ENV=development
And, here's the command I run...
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
The command fails with below error
Attaching to nestjs-api-server_app_1
app_1 |
app_1 | > [email protected] start /usr/src/app
app_1 | > npm run copy-resources && nodemon --watch src -e ts,tsx --exec ts-node src/main.ts
app_1 |
app_1 |
app_1 | > [email protected] copy-resources /usr/src/app
app_1 | > ts-node scripts/copy-resources.ts
app_1 |
app_1 | sh: 1: ts-node: not found
app_1 | npm ERR! code ELIFECYCLE
app_1 | npm ERR! syscall spawn
app_1 | npm ERR! file sh
app_1 | npm ERR! errno ENOENT
app_1 | npm ERR! [email protected] copy-resources: `ts-node scripts/copy-resources.ts`
app_1 | npm ERR! spawn ENOENT
app_1 | npm ERR!
app_1 | npm ERR! Failed at the [email protected] copy-resources script.
app_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
app_1 | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
app_1 |
app_1 | npm ERR! A complete log of this run can be found in:
app_1 | npm ERR! /root/.npm/_logs/2020-02-27T20_07_39_822Z-debug.log
app_1 | npm ERR! code ELIFECYCLE
app_1 | npm ERR! errno 1
app_1 | npm ERR! [email protected] start: `npm run copy-resources && nodemon --watch src -e ts,tsx --exec ts-node src/main.ts`
app_1 | npm ERR! Exit status 1
app_1 | npm ERR!
app_1 | npm ERR! Failed at the [email protected] start script.
app_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
app_1 | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
app_1 |
app_1 | npm ERR! A complete log of this run can be found in:
app_1 | npm ERR! /root/.npm/_logs/2020-02-27T20_07_39_847Z-debug.log
nestjs-api-server_app_1 exited with code 1
Upvotes: 2
Views: 6685
Reputation: 112
Hey i tried this solution and it worded with me, i hope it works with you as well https://stackoverflow.com/a/50454232/13549437
The basic idea is that we are going to invoke the ts-node from node_modules folder rather than from the local /bin folders (the global commands folder).
Install ts-node and typescript npm i ts-node typescript
The start script in the package.json "start": "./node_modules/.bin/ts-node index.ts"
The run script in the docker file RUN npm install
Upvotes: 2