感谢您的帮助!
我有以下Dockerfile:
FROM node:slim
RUN mkdir -p /project
WORKDIR /project
# workdir is empty
RUN ls -a
COPY . /project
# workdir is full
RUN ls -a
# this command create node_modules folder on it own
RUN npm install
# I have node_modules folder with packages
RUN ls -a
RUN ls -d node_modules/*
最后的输出是:
Step 8/9 : RUN ls -a
---> Running in 90d8793f491a
.
..
.babelrc
.editorconfig
.eslintignore
.eslintrc.js
.git
.gitignore
.postcssrc.js
Dockerfile-dev
README.md
build
config
docker-compose.dev.yml
index.html
node_modules
package-lock.json
package.json
src
static
test
Removing intermediate container 90d8793f491a
---> b563d272b270
Step 9/9 : RUN ls -d node_modules/*
---> Running in a14bb4024e5e
node_modules/@babel
node_modules/@types
node_modules/abab
node_modules/abbrev
node_modules/accepts
node_modules/acorn
但是当我从以下命令查看容器的文件时:
docker-compose -f docker-compose.dev.yml run project ls
我没有 node_modules 文件夹(带有依赖项的文件夹),因为它无法启动我的容器:
docker-compose -f docker-compose.dev.yml up
sh: 1: webpack-dev-server: not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! project@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the project@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-04-11T19_09_35_669Z-debug.log
docker-compose 很简单:
version: '3'
services:
project:
container_name: project
build:
context: .
dockerfile: Dockerfile-dev
command: npm run dev
volumes:
- .:/project
ports:
- 8080:8080
问题是:为什么会发生?如何解决问题?
答案 0 :(得分:-4)