[英]Can't run sample express app in node container on Windows
I'm watching a Docker course from Pluralsight and I need to run a Docker source on a Docker container I just downloaded. 我正在从Pluralsight看Docker课程,我需要在刚下载的Docker容器上运行Docker源代码。
Even though I have package.json
file in the current path, it is not recognized. 即使我在当前路径中有
package.json
文件,也无法识别它。
Usuario@RE MINGW64 /d/node/ExpressSite
$ docker run -p 8080:3000 -v /$(pwd):/var/www -w "/var/www" node:4.4.5 npm start
npm info it worked if it ends with ok
npm info using npm@2.15.5
npm info using node@v4.4.5
npm ERR! Linux 4.4.12-boot2docker
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v4.4.5
npm ERR! npm v2.15.5
npm ERR! path /var/www/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/var/www/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /var/www/npm-debug.log
Why the Pluralsight does the same and it works? 为什么Pluralsight会这样做并且有效? What's wrong with my version?
我的版本有什么问题?
From official docs https://docs.docker.com/engine/userguide/containers/dockervolumes/ : 从官方文档https://docs.docker.com/engine/userguide/containers/dockervolumes/ :
If you are using Docker Machine on Mac or Windows, your Engine daemon has only limited access to your OS X or Windows filesystem.
如果在Mac或Windows上使用Docker Machine,则Engine守护程序仅具有对OS X或Windows文件系统的有限访问权限。 Docker Machine tries to auto-share your /Users (OS X) or C:\\Users (Windows) directory.
Docker Machine尝试自动共享您的/ Users(OS X)或C:\\ Users(Windows)目录。 So, you can mount files or directories on OS X using.
因此,您可以使用在OS X上挂载文件或目录。
docker run -v /Users/<path>:/<container path> ...
On Windows, mount directories using:
在Windows上,使用以下命令挂载目录:
docker run -v /c/Users/<path>:/<container path> ...
So, you can create a directory inside C:\\Users\\<your_username>
( code
for example) with your code and mount it inside the container like so: 所以,你可以创建中的目录
C:\\Users\\<your_username>
( code
与您的代码为例)并安装它像这样的容器内:
docker run -p 8080:3000 -v /c/Users/<your_username>/code:/var/www -w "/var/www" node:4.4.5 npm start
Please note that your code will be available inside the container in /var/www/
directory 请注意,您的代码将在
/var/www/
目录的容器内可用
pwd
returns /c/Users/<my_username>
. pwd
返回/c/Users/<my_username>
。 Try it yourself in Docker terminal. 在Docker终端中尝试一下。
You can use pwd
for convenience sake: 为了方便起见,可以使用
pwd
:
docker run -p 8080:3000 -v $(pwd)/code:/var/www -w "/var/www" node:4.4.5 npm start
Good luck with the course and Dockerize all the things! 该课程祝您好运,并将所有内容都进行Dockerize!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.