[英]Can't debug when using `docker-compose run`, but `docker-compose up` works
[英]Docker and Node - Getting “ELIFECYCLE” when using docker-compose, works with `docker run`
這使我瘋狂了幾個小時。 我想要一個docker-compose文件,該文件將簡單地構建映像,創建容器,然后執行簡單的腳本。
我已經盡可能簡單地重新創建了這個問題
app.js
const fs = require("fs");
const util = require("util");
const sqlite3 = require("sqlite3");
console.log("DOING NOTHING");
的package.json
{
"name": "example",
"version": "0.1.0",
"author": "shatnerz",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"sqlite3": "4.0.0"
}
}
Dockerfile
FROM node:9.11.1-alpine
ADD . /home/example
WORKDIR /home/example
# RUN npm update -g
RUN npm install
CMD ["npm", "run", "start"]
泊塢窗,compose.yml
version: '3.6'
services:
example:
build: .
image: shatnerz/example
container_name: shatnerz-example
volumes:
- .:/home/example
command: ["npm", "run", "start"]
當我嘗試使用docker compose時
$ docker-compose up --build
Building example-test
Step 1/5 : FROM node:9.11.1-alpine
---> 7af437a39ec2
Step 2/5 : ADD . /home/example
---> Using cache
---> cbb4467e0651
Step 3/5 : WORKDIR /home/example
---> Using cache
---> 377b15cc8eab
Step 4/5 : RUN npm install
---> Using cache
---> 03be15a4465b
Step 5/5 : CMD ["npm", "run", "start"]
---> Using cache
---> 286312488783
Successfully built 286312488783
Successfully tagged shatnerz/example:latest
Starting shatnerz-example ... done
Attaching to shatnerz-example
shatnerz-example |
shatnerz-example | > example@0.1.0 start /home/example
shatnerz-example | > node app.js
shatnerz-example |
shatnerz-example | internal/modules/cjs/loader.js:550
shatnerz-example | throw err;
shatnerz-example | ^
shatnerz-example |
shatnerz-example | Error: Cannot find module 'sqlite3'
shatnerz-example | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
shatnerz-example | at Function.Module._load (internal/modules/cjs/loader.js:475:25)
shatnerz-example | at Module.require (internal/modules/cjs/loader.js:598:17)
shatnerz-example | at require (internal/modules/cjs/helpers.js:11:18)
shatnerz-example | at Object.<anonymous> (/home/example/app.js:3:17)
shatnerz-example | at Module._compile (internal/modules/cjs/loader.js:654:30)
shatnerz-example | at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
shatnerz-example | at Module.load (internal/modules/cjs/loader.js:566:32)
shatnerz-example | at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
shatnerz-example | at Function.Module._load (internal/modules/cjs/loader.js:498:3)
shatnerz-example | npm ERR! code ELIFECYCLE
shatnerz-example | npm ERR! errno 1
shatnerz-example | npm ERR! example@0.1.0 start: `node app.js`
shatnerz-example | npm ERR! Exit status 1
shatnerz-example | npm ERR!
shatnerz-example | npm ERR! Failed at the example@0.1.0 start script.
shatnerz-example | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
shatnerz-example | npm WARN Local package.json exists, but node_modules missing, did you mean to install?
shatnerz-example |
shatnerz-example | npm ERR! A complete log of this run can be found in:
shatnerz-example | npm ERR! /root/.npm/_logs/2018-04-18T06_39_32_565Z-debug.log
shatnerz-example exited with code 1
我嘗試了不同版本的節點,並使用ubuntu映像而不是alpine無效。 我基本上在每種情況下都遇到此錯誤,但是以某種方式docker run shatnerz/example
可以正常工作。
$ docker run shatnerz/example
> example@0.1.0 start /home/example
> node app.js
DOING NOTHING
這真令人沮喪。 我凝視了太久了。 我不再進步了。 我還將docker-compose和docker更新到最新版本。
我的.dockerignore
有node-modules*
編輯:有趣的是,當嘗試從sublime運行app.js時,我收到類似的錯誤,這導致認為它可能與stdin和stdout有關
嘗試從docker-compose.yml中刪除以下行
volumes:
- .:/home/example
command: ["npm", "run", "start"]
由於您已經在docker-image中添加了這些參數和必需的文件。
請告訴我-您的輸出,以便我進一步幫助您。
奇怪的是,我已經能夠通過直接在計算機上運行sudo npm install
來解決相同的錯誤消息,然后通過docker-compose down
和docker-compose up --build
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.