我試圖運行我的項目與泊塢內的所有依賴關係,但我被卡住了咕嚕依賴,出於某種原因咕嚕失敗,它可以發生錯誤找不到當地的咕嚕聲。錯誤在Docker中運行grunt:致命錯誤:無法找到本地grunt
我創建的如何重現這樣的一個例子:
.
├── code
│ ├── bower.json
│ ├── Gruntfile.js
│ └── package.json
├── docker-compose.yml
└── frontend.dockerfile
搬運工-compose.yml:
version: "2"
services:
frontend:
build:
context: .
dockerfile: frontend.dockerfile
ports:
- "8585:8000"
volumes:
- ./code:/srv/frontend
command: grunt
frontend.dockerfile:
FROM node:wheezy
ADD code /srv/frontend
WORKDIR /srv/frontend
RUN npm install -g grunt-cli bower
RUN npm install
RUN groupadd -r usergroup && useradd -m -r -g usergroup user
RUN chown -R user:usergroup /srv/frontend
USER user
RUN bower install
bower.json:
{
"name": "code",
"description": "",
"main": "index.js",
"authors": [
"Mr. No One"
],
"license": "ISC",
"homepage": "",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular": "^1.5.8"
}
}
Gruntfile.json:
module.exports = function(grunt) {
grunt.initConfig({});
// tasks
grunt.registerTask('default', []);
};
的package.json:
{
"name": "code",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "^1.0.1"
}
}
$ docker-compose up ... installing all dependencies ...
安裝後,它在嘗試運行失敗我指定的grunt
命令指明分數在我docker-compose.yml
文件與此錯誤:
frontend_1 | grunt-cli: The grunt command line interface (v1.2.0)
frontend_1 |
frontend_1 | Fatal error: Unable to find local grunt.
frontend_1 |
frontend_1 | If you're seeing this message, grunt hasn't been installed locally to
frontend_1 | your project. For more information about installing and configuring grunt,
frontend_1 | please see the Getting Started guide:
frontend_1 |
frontend_1 | http://gruntjs.com/getting-started
package.json
實際上幷包括grunt
作爲一個依賴,所以應該RUN npm install
後進行安裝。
貌似唯一node_modules文件夾我是'''在/ usr /本地/ lib/node_modules''',node_modules和bower_components實際上是從項目文件夾中丟失的。 'NODE_ENV'''沒有設置。 – vladimirze
你的'package.json'是否存在於'WORKDIR'中? –
同時在你的'command'裏放一個'cwd'來看看它在哪裏試圖運行grunt。 –