[英]Docker Volume: ENOENT: no such file or directory, open '/app/package.json'
I'm using Docker using Docker Toolbox because of I have Windows Home.我使用 Docker 使用 Docker 工具箱,因为我有 Windows 主页。 I made a React application using:
我使用以下方法制作了一个 React 应用程序:
npx create-react-app frontend
Thus I made a "Dokerfile.dev" file in which I say doicker to use base image node alpine version, setting working directory "/app", to copy "package.json" that needs to install node "run npm install", and then I say to copy the other files.因此,我制作了一个“Dokerfile.dev”文件,其中我说 doicker 使用基本映像节点 alpine 版本,设置工作目录“/app”,复制需要安装节点“run npm install”的“package.json”,以及然后我说复制其他文件。 I put also the command to be enable when I start that container:
当我启动该容器时,我还设置了要启用的命令:
FROM node:alpine WORKDIR '/app' COPY package.json. RUN npm install COPY. . CMD ["npm","run","start"]
And seems work, because of if I build:似乎工作,因为如果我建立:
docker build -f Dockerfile.dev .
and run it mapping container port to local port (3000):并运行它将容器端口映射到本地端口(3000):
docker run -it -p 3000:3000 [containerID]
it works on http://192.168.99.100:3000 , react page working.它适用于http://192.168.99.100:3000 ,反应页面工作。
After that, I wanna try to run using volume.之后,我想尝试使用音量运行。 Actually I delete node_modules dependency from "app" folder, because of npm install it double.
实际上我从“app”文件夹中删除了 node_modules 依赖项,因为 npm 将它安装双倍。 This I put it like a placeholder.
我把它当作占位符。 Instead, I map the Present Working Directory (pwd) with "/app":
相反,我用“/app” map 当前工作目录(密码):
docker ruyn -it -p 3000:3000 -v /app/node_modules -v /c/Program\ Files/Docker\ Toolbox/frontend:/app -e CHOKIDAR_USEPOLLING=true a631964d87b2
(my pwd contains whitespaces, thus I have to use "\ " isntead of "". "a631964d87b2" is my container id) (我的密码包含空格,因此我必须使用“\”而不是“”。“a631964d87b2”是我的容器 ID)
The result is:结果是:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /app/package.json
npm ERR! errno -2
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/2020-05-23T20_10_26_143Z-debug.log
Why it works without Volume, instead using volume it says that it doesn't found /app/package.json?为什么它在没有音量的情况下工作,而不是使用音量它说它没有找到 /app/package.json? That's impossible because of in Dockerfile.dev I say:
这是不可能的,因为在 Dockerfile.dev 我说:
COPY package.json .
thus to copy package.json to the current working directory which is "/app".因此将 package.json 复制到当前工作目录“/app”。
--- UPDATE - - 更新
Actually it works if I move project inside c:/Users/username实际上,如果我将项目移动到 c:/Users/username
and I text this:我发短信说:
docker run -it -p 3000:3000 -v /app/node_modules -v $(pwd):/app -e CHOKIDAR_USEPOLLING=true a631964d87b2
That's because $(pwd) puts my Present Working Directory, and in that case it doesn't have whitespaces inside it.那是因为 $(pwd) 放置了我的当前工作目录,在这种情况下,它里面没有空格。 How I can put my plan working directory with namespaces?
如何将我的计划工作目录与命名空间一起放置?
--- UPDATE 2 --- 更新 2
problem are not whitespaces: I tried to modify c:/Users/username/frontend in c:/Users/username/abc\ frontend问题不是空格:我试图在 c:/Users/username/abc\ frontend 中修改 c:/Users/username/frontend
and it still works.它仍然有效。 It seems that project must be in users and not in program files?
似乎项目必须在用户中而不是在程序文件中?
The problem was that project was outside Window Users folder, in fact it was in Program Files.问题是项目在 Window 用户文件夹之外,实际上它在程序文件中。 Trying to move it in Users/myUser, it works also using a path with whitespaces
试图在用户/我的用户中移动它,它也可以使用带有空格的路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.