gpt4 book ai didi

node.js - 错误 "enoent ENOENT: no such file or directory, open '/app/package.json'"docker 引用外部文件夹

转载 作者:太空宇宙 更新时间:2023-11-03 22:23:34 24 4
gpt4 key购买 nike

我的整个 nodejs 代码位于 abc 文件夹中

root@ip-10-0-0-9:~/standalone/apiserver# ls
Dockerfile abc
root@ip-10-0-0-9:~/standalone/apiserver/abc# ls
build index.html node_modules package.json package-lock.json src

我通过以下方式创建了 Dockerfile:

FROM node:10
#Create app directory
WORKDIR /app
COPY abc/package*.json /app/
RUN npm install
CMD ["npm","start"]

当我按以下方式运行 docker 容器时,出现错误:

docker build -t node-app .

root@ip-10-0-0-9:~/standalone/apiserver# docker run -it --net=host -v /abc:/app --name mynodeapp1 node-app
npm ERR! path /app/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-05-14T14_36_09_651Z-debug.log

更新:

package.json文件内容如下:

{
"name": "abc",
"description": "A Vue.js project",
"version": "1.0.0",
"author": "utkarsh",
"license": "MIT",
"private": true,
"scripts": {
"start": "nodemon src/server.js",
"lint": "eslint **/*.js"
},
"dependencies": {
"body-parser": "^1.18.2",
"cors": "^2.8.4",
"express": "^4.16.2",
"jquery": "^3.3.1",
"moment": "^2.20.1",
"morgan": "^1.9.0",
"mysql": "^2.15.0",
"nodemon": "^1.14.12"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^5.0.5",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
}
}

最佳答案

我稍微修改了您的 Dockerfile,它现在似乎可以在这里工作。

Dockerfile:

FROM node:10
#Create app directory
WORKDIR /app
COPY abc/package*.json ./
RUN ls -al
RUN npm install
CMD ["npm","start"]

您可以删除RUN ls -al,我把它放在那里只是为了查看workdir的内容,并且它打印了文件。

更改是 - 您已经通过设置 WORKDIR 指定了所有工作应该完成的位置,基于我在 COPY 时设置的路径> 在那儿。

尝试一下是否有效并回发;)

关于node.js - 错误 "enoent ENOENT: no such file or directory, open '/app/package.json'"docker 引用外部文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50333136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com