当前位置: 首页 > 知识库问答 >
问题:

Docker错误:没有这样的文件或目录,请打开'/包。带有NestJs应用程序的json

席银龙
2023-03-14

我试图在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还是个新手---

共有1个答案

欧阳鸿哲
2023-03-14

在这里,问题是,我如何以及在何处将我的包*. json复制到目标文件夹。由于我的docker compose文件在根目录中,而我的Dockerfilebackend文件夹中。复制命令应类似于backend/pack*. json./

此外,用于调试问题。我刚刚找到我最后一个成功的步骤图像。并尝试在该图像中运行步骤(导致问题),以获得更多见解。

希望将来有人能从中得到一些帮助。

 类似资料:
  • 我在节点Js中工作。当我尝试加载文件时:moviedata.json,如下行: 显示: 错误:ENOENT:没有这样的文件或目录,打开'./moviedata.json'在错误(本机)在Object.fs.open同步(fs.js:640: 18)在Object.fs.readFileSync(fs.js:508: 33)在对象。(/用户/dortiz/文档/NodeJS/pruebas/zw/a

  • 问题内容: 我在运行docker文件时收到来自docker的错误消息。就是说/ var / lib / docker / aufs / layers / xxxx:运行Docker build时没有这样的文件或目录。 我尝试了多种方法来删除容器和图像,因此我对此非常有兴趣。 任何 Docker文件为: 完整的控制台输出为: 编辑 @BMitchs的建议解决了该问题: rm -rf / var /

  • 方法总是给出这样的错误: 打开失败:ENOENT(没有这样的文件或目录)

  • 试图渲染文件从'视图'目录从'路由',但得到以下错误: 错误: 有效登录 {[Error:enoint:没有这样的文件或目录,打开'/views/s.ejs'] 错误号:-2, 代码:'enoint', 系统调用:'open', 路径:'./views/s.ejs'} [0mPOST/afterSignIn[32m200[0m77.339 ms-[0m 目录结构:

  • 问题内容: 我正在使用Ubuntu 14.04。我有以下代码: 但我不断收到以下错误: python程序和图像都在同一位置。可能是什么问题? 问题答案: 您需要安装:

  • 错误:警告:require_once(…/tcpdf/config/lang):无法打开流:在第33行的C:\xampp\htdocs\jmb_system\anggerik\printunitstmt.php中没有这样的文件或目录 致命错误:require_once():失败打开需要'…/tcpdf/config/lang'(include_path='.; C:\xampp\php\PEAR'