【发布时间】:2017-12-14 15:25:33
【问题描述】:
我被这个错误困扰了一整天。当我尝试运行我的 docker 容器时,出现错误Segmentation fault (core dumped)。
所以为了重现这个错误,我将提供我的环境和代码。
下面第一个是Dockerfile,没什么特别的:
FROM node:8.1.3-alpine
RUN apk add --no-cache --update krb5-dev alpine-sdk python
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 3000
CMD [ "npm", "start" ]
问题在于调用我的npm start 脚本,它总是在具有此命令"test-prod": "mocha test/**/*", 的npm run test-prod 处失败。如果我从 npm 中删除它,则开始站点部署没有错误。
Test-prod 是从第一个测试开始的,它使用 supertest 导入 app.js:
const { describe, it, before, after } = require('mocha');
const request = require('supertest');
const app = require('../../../app.js');
const User = require('../../../models/User');
const agent = request.agent(app);
//some tests
我想它可以与新的 mongoose 版本 4.11 绑定,它要求 auth 并传入选项对象,但是当我通过它时,它警告我这是错误的:
the options [user] is not supported
the options [pass] is not supported
最后是app.js下面的主要部分:
require('dotenv').config();
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const session = require('express-session');
const mongoose = require('mongoose');
const MongoStore = require('connect-mongo')(session);
const routes = require('./routes');
const app = express();
const URI = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test' ? 'mongodb://localhost/mulibwanji' : process.env.MONGODB_URI;
mongoose.connect(URI, { // In URI also I have user and pass as expected
useMongoClient: true,
user: 'login',
pass: 'pass',
});
以及来自 Docker 日志的错误:
2017-07-10T18:53:49.796105113Z
2017-07-10T18:53:49.802949762Z
2017-07-10T18:53:49.814928711Z Local strategy authentication
2017-07-10T18:53:49.826690115Z Login
2017-07-10T18:53:51.226982330Z Segmentation fault (core dumped)
2017-07-10T18:53:51.258175441Z npm info lifecycle mulibwanji@0.0.0~test-prod: Failed to exec test-prod script
2017-07-10T18:53:51.258270885Z npm ERR! code ELIFECYCLE
2017-07-10T18:53:51.258406077Z npm ERR! errno 139
2017-07-10T18:53:51.258445569Z npm ERR! mulibwanji@0.0.0 test-prod: `mocha test/**/*`
2017-07-10T18:53:51.258519335Z npm ERR! Exit status 139
2017-07-10T18:53:51.258539503Z npm ERR!
2017-07-10T18:53:51.258579954Z npm ERR! Failed at the mulibwanji@0.0.0 test-prod script.
2017-07-10T18:53:51.258617042Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
还有这里的堆栈跟踪:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@5.0.3
3 info using node@v8.1.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle mulibwanji@0.0.0~prestart: mulibwanji@0.0.0
6 silly lifecycle mulibwanji@0.0.0~prestart: no script for prestart, continuing
7 info lifecycle mulibwanji@0.0.0~start: mulibwanji@0.0.0
8 verbose lifecycle mulibwanji@0.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle mulibwanji@0.0.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/usr/src/app/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
10 verbose lifecycle mulibwanji@0.0.0~start: CWD: /usr/src/app
11 silly lifecycle mulibwanji@0.0.0~start: Args: [ '-c',
11 silly lifecycle 'npm run build && npm run test-prod && npm run lint && npm run update-schema && node ./bin/www' ]
12 silly lifecycle mulibwanji@0.0.0~start: Returned: code: 139 signal: null
13 info lifecycle mulibwanji@0.0.0~start: Failed to exec start script
14 verbose stack Error: mulibwanji@0.0.0 start: `npm run build && npm run test-prod && npm run lint && npm run update-schema && node ./bin/www`
14 verbose stack Exit status 139
14 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:283:16)
14 verbose stack at emitTwo (events.js:125:13)
14 verbose stack at EventEmitter.emit (events.js:213:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:125:13)
14 verbose stack at ChildProcess.emit (events.js:213:7)
14 verbose stack at maybeClose (internal/child_process.js:897:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)
15 verbose pkgid mulibwanji@0.0.0
16 verbose cwd /usr/src/app
17 verbose Linux 4.11.9-coreos
18 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
19 verbose node v8.1.3
20 verbose npm v5.0.3
21 error code ELIFECYCLE
22 error errno 139
23 error mulibwanji@0.0.0 start: `npm run build && npm run test-prod && npm run lint && npm run update-schema && node ./bin/www`
23 error Exit status 139
24 error Failed at the mulibwanji@0.0.0 start script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 139, true ]
如果有任何建议,我将不胜感激,谢谢。
【问题讨论】:
-
您的项目是否直接/间接使用任何已编译的插件?如果是这样,您可能需要在容器内
npm rebuild。 -
@mscdex 我不确定,但我已经这样做了,以防万一,它没有解决问题(
-
您解决了吗?我遇到了类似的问题,可能是 bcrypt 与节点 8 中的 v8 版本存在兼容性问题。github.com/nodejs/node/issues/14069
-
@jishi no(我现在已经回到7.8了
-
这很奇怪,它似乎在 8.1.3 上工作,但突然间它停止在相同的节点版本和相同的 bcrypt 版本上工作。但如果降级是一种选择,那至少是目前的解决方案。我会试试的,谢谢。
标签: node.js unix docker mongoose mocha.js