【问题标题】:Can't run sample express app in node container on Windows无法在 Windows 上的节点容器中运行示例 express 应用程序
【发布时间】:2016-06-18 17:51:03
【问题描述】:

我正在观看 Pluralsight 的 Docker 课程,我需要在刚刚下载的 Docker 容器上运行 Docker 源代码。

即使我在当前路径中有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

为什么 Pluralsight 会做同样的事情并且有效?我的版本有什么问题?

【问题讨论】:

    标签: node.js docker


    【解决方案1】:

    来自官方文档https://docs.docker.com/engine/userguide/containers/dockervolumes/

    如果您在 Mac 或 Windows 上使用 Docker Machine,您的引擎守护程序只能有限地访问您的 OS X 或 Windows 文件系统。 Docker Machine 尝试自动共享您的 /Users (OS X) 或 C:\Users (Windows) 目录。因此,您可以在 OS X 上使用挂载文件或目录。

    docker run -v /Users/<path>:/<container path> ...

    在 Windows 上,使用以下方式挂载目录:

    docker run -v /c/Users/<path>:/<container path> ...

    因此,您可以使用您的代码在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

    请注意,您的代码将在容器内的/var/www/ 目录中可用

    pwd 返回/c/Users/<my_username>。在 Docker 终端中自己尝试一下。


    为方便起见,您可以使用pwd

    docker run -p 8080:3000 -v $(pwd)/code:/var/www -w "/var/www" node:4.4.5 npm start

    祝你在课程中好运,并将所有东西 Dockerize 化!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 2020-05-24
      • 2020-04-20
      • 2015-01-31
      • 1970-01-01
      • 2014-10-08
      相关资源
      最近更新 更多