我在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"
}
}
答案 0 :(得分:0)
我已经修改了你的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
。
尝试它是否有效并回发;)
答案 1 :(得分:-1)
我有这个确切的错误,事实证明这是docker-compose的问题。对我来说,我在Windows中运行WSL,并且WSL中安装的docker-compose版本无法正确处理卷绑定。我通过卸载/usr/local/bin/docker-compose
并改用Windows exe alias docker-compose="/mnt/c/Program\ Files/Docker/Docker/resources/bin/docker-compose.exe"
如果您不在Windows上,请尝试update your version of docker-compose