npm在Docker内部安装后访问node_modules [英] Accessing node_modules after npm install inside Docker

查看:206
本文介绍了npm在Docker内部安装后访问node_modules的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac上使用Docker Machine运行Docker。我已经成功设置了一些容器并在其中运行了npm安装,如此处。这会将node_modules安装在映像内和容器内,但是它们在主机上不可用,即我的IDE抱怨缺少node_modules。

I am running Docker with Docker Machine on Mac. I successfully set up some containers and ran npm install inside them, as explained here. This installs the node_modules inside the image and inside the container, but they are not available on the host, i.e. my IDE complains about missing node_modules.

我缺少什么吗?在容器中运行npm install但能够在主机上进行开发(具有这些依赖项)的最佳方法是什么?

Am I missing something? What is the best way to run npm install inside the container but be able to do development (with these dependencies) on the host?

从我的docker-compose.yml中:

From my docker-compose.yml:

  volumes:
    - /Users/andre/IdeaProjects/app:/home/app
    - /home/app/node_modules


推荐答案

由于您使用的是 boot2docker ,仅最大主机文件夹 / Users / 被挂载并可以从boot2docker host。

Since you are using boot2docker, only Max host folder /Users/ is mounted and accessible from the boot2docker host.

这意味着您需要将 / home / app / node_modules 映射到Mac主机路径与 / Users 一起查看Mac主机上的上述模块。

That means you would need to map /home/app/node_modules to a Mac host path starting with /Users, to see said modules on your Mac host.

volumes:
    - /Users/andre/IdeaProjects/app:/home/app
    - /Users/andre/node_modules:/home/app/node_modules

这篇关于npm在Docker内部安装后访问node_modules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆