简体   繁体   English

Node.js模块不在Docker中构建

[英]Node.js modules not building in Docker

I'm building this dockerfile using docker-compose and I need it to build native modules in docker (not just copy them from local). 我正在使用docker-compose构建此dockerfile,我需要它在docker中构建本机模块(而不仅仅是从本地复制它们)。 This only works when my local modules are built (npm install) As soon as I delete them this runs but there is no node_modules directory and it gives an error: Error: Cannot find module 'express' 这仅在构建本地模块(npm install)时才有效,一旦删除它们,它就会运行,但是没有node_modules目录,并且会显示错误:错误:找不到模块“ express”

FROM mhart/alpine-node:6
MAINTAINER Me

COPY package.json index.js lib /app/

WORKDIR /app

RUN apk add --no-cache make gcc g++ python && \
  addgroup -S app && adduser -S -g app app && \
  npm install && \
  npm cache clean && \
  apk del make gcc g++ python

USER app

And here is the app directory: 这是应用程序目录:

.dockerignore
.eslintignore
.eslintrc.js
Dockerfile
docker-compose.yml
index.js
lib
npm-debug.log
package.json

The problem was with the way docker binds the app folder from the host to the container. 问题在于docker将应用文件夹从主机绑定到容器的方式。 The second line in the volume section from my docker-compose.yml fixed it. 我的docker-compose.yml中volume部分的第二行对其进行了修复。

volumes:
  - .:/app
  - /app/node_modules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM