I'm trying to run a node image(with nestJS application) inside docker but I have this error:
*$ docker compose build
[+] Building 7.3s (11/11) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 747B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/node:12.22.4-alpine 6.6s
=> [auth] library/node:pull token for registry-1.docker.io 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 10.04kB 0.0s
=> [development 1/6] FROM docker.io/library/node:12.22.4-alpine@sha256:78be4f61c7a0f00cc9da47e3ba2f1bacf9ba 0.0s
=> CACHED [development 2/6] WORKDIR /project/sawtooth-tuna/backend 0.0s
=> CACHED [development 3/6] COPY package*.json ./ 0.0s
=> CACHED [development 4/6] RUN npm install --only=development 0.0s
=> [development 5/6] COPY . . 0.1s
=> ERROR [development 6/6] RUN cd /project/sawtooth-tuna/backend && npm run build 0.5s
------
> [development 6/6] RUN cd /project/sawtooth-tuna/backend && npm run build:
#0 0.507 npm ERR! code ENOENT
#0 0.508 npm ERR! syscall open
#0 0.508 npm ERR! path /project/sawtooth-tuna/backend/package.json
#0 0.509 npm ERR! errno -2
#0 0.510 npm ERR! enoent ENOENT: no such file or directory, open '/project/sawtooth-tuna/backend/package.json'
#0 0.510 npm ERR! enoent This is related to npm not being able to find a file.
#0 0.510 npm ERR! enoent
#0 0.516
#0 0.516 npm ERR! A complete log of this run can be found in:
#0 0.516 npm ERR! /root/.npm/_logs/2022-05-17T00_58_30_434Z-debug.log
------
failed to solve: executor failed running [/bin/sh -c cd /project/sawtooth-tuna/backend && npm run build]: exit code: 254
I have read all the available posts related to this topic. But no luck -
My docker file
# Download base image
FROM node:12.22.4-alpine As development
# Define Base Directory
WORKDIR /project/sawtooth-tuna/backend
# Copy and restore packages
COPY package*.json ./
RUN npm install --only=development
# Copy all other directories
COPY . .
# Setup base command
RUN npm run build
# # second phase
FROM node:12.22.4-alpine As production
# Declaring working directory
WORKDIR /project/sawtooth-tuna/backend
COPY package*.json ./
RUN npm install --only=production
#Copy build artifacts
COPY --from=builder /project/sawtooth-tuna/backend/dist ./
COPY --from=builder /project/sawtooth-tuna/backend/config ./config
# Start the server
CMD [ "node", "main.js" ]
As I am using docker-compose -
tunachain-backend:
build:
context: .
target: development
dockerfile: ./backend/Dockerfile
image: hyperledger/tunachain-backend
container_name: tunachain-backend
volumes:
- .:/project/sawtooth-tuna/backend
- /project/sawtooth-tuna/backend/node_modules
command: npm run start:dev
ports:
- 3001:3001
- 9229:9229
My project structure -
backend -
NestJs application code
Dockerfile
docker-compose
- Any suggestion or any hint(how should I debug the issue). Fairly new with docker ---