Docker error: no such file or directory, open '/package.json' with NestJs application
Docker error: no such file or directory, open '/package.json' with NestJs application
我正在尝试 运行 在 docker 中创建一个节点图像(带有 nestJS 应用程序),但出现此错误:
*$ 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
我已阅读与此主题相关的所有可用帖子。但没有运气 -
我的docker文件
# 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" ]
因为我正在使用 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
我的项目结构-
backend -
NestJs application code
Dockerfile
docker-compose
- 任何建议或任何提示(我应该如何调试问题)。 docker 相当新 ---
这里的问题是,我如何以及在何处将我的包*.json 复制到目标文件夹。因为我的 docker compose
文件在根目录中,而我的 Dockerfile
在 backend
文件夹中。复制命令应类似于 backend/package*.json ./
.
另外,用于调试问题。我刚刚找到我最后一次成功的步骤图像。然后 sh
进入它并尝试 运行 该图像中的步骤(导致问题),以获得更多见解。
希望以后有人能从中得到一些帮助。
我正在尝试 运行 在 docker 中创建一个节点图像(带有 nestJS 应用程序),但出现此错误:
*$ 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
我已阅读与此主题相关的所有可用帖子。但没有运气 -
我的docker文件
# 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" ]
因为我正在使用 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
我的项目结构-
backend -
NestJs application code
Dockerfile
docker-compose
- 任何建议或任何提示(我应该如何调试问题)。 docker 相当新 ---
这里的问题是,我如何以及在何处将我的包*.json 复制到目标文件夹。因为我的 docker compose
文件在根目录中,而我的 Dockerfile
在 backend
文件夹中。复制命令应类似于 backend/package*.json ./
.
另外,用于调试问题。我刚刚找到我最后一次成功的步骤图像。然后 sh
进入它并尝试 运行 该图像中的步骤(导致问题),以获得更多见解。
希望以后有人能从中得到一些帮助。