在docker镜像下构建平均堆栈应用程序时忽略npm安装错误

时间:2017-11-07 09:30:24

标签: node.js docker

我有一个平均堆栈应用程序,我正在docker容器下构建。但是在执行npm install时抛出一些错误并不重要。我想忽略所有的错误。

这就是我想要的: -

# Create image based on the official Node 6 image from dockerhub
FROM node:6

# Create a directory where our app will be placed
RUN mkdir -p ./build


# Copy dependency definitions
COPY package.json ./build

# Change directory so that our commands run inside this new directory(It will switch the directory as well)
WORKDIR ./build

# Install npm dependecies
RUN npm install || 1


# Get all the code needed to run the app
COPY . ./build

# Expose the port the app runs in
EXPOSE 8100

# Serve the app
CMD ["npm", "start"]

我的package.json文件是

{
  "name": "mean1",
  "version": "0.0.0",
  "main": "server/app.js",
  "dependencies": {
    "adm-zip": "^0.4.7",
    "async": "^2.1.4",
    "aws-sdk": "^2.101.0",
    "body-parser": "~1.5.0",
    "composable-middleware": "^0.3.0",
    "compression": "~1.0.1",
    "connect-mongo": "^0.8.1",
    "cookie-parser": "~1.0.1",
    "cors": "^2.7.1",
    "crypto": "0.0.3",
    "debug": "^2.6.0",
    "ejs": "~0.8.4",
    "errorhandler": "~1.0.0",
    "express": "~4.9.0",
    "express-jwt": "^3.0.0",
    "express-session": "~1.0.2",
    "fs.extra": "^1.3.2",
    "gm": "^1.21.1",
    "handlebars": "^4.0.5",
    "html-minifier": "^3.4.2",
    "html-pdf": "^2.1.0",
    "json2xls": "^0.1.2",
    "jsonwebtoken": "^5.0.0",
    "lodash": "~3.10.1",
    "lwip": "0.0.9",
    "method-override": "~1.0.0",
    "moment": "^2.17.1",
    "mongoose": "~4.10.0",
    "morgan": "~1.0.0",
    "multer": "^1.0.6",
    "newrelic": "^2.2.0",
    "nodemailer": "~1.8.0",
    "passport": "~0.2.0",
    "passport-facebook": "^2.1.0",
    "passport-google-oauth": "latest",
    "passport-linkedin": "^1.0.0",
    "passport-local": "~0.1.6",
    "passport-twitter": "^1.0.4",
    "request": "~2.65.0",
    "rimraf": "^2.6.1",
    "s3": "^4.4.0",
    "seq": "^0.3.5",
    "serve-favicon": "~2.0.1",
    "socketio-jwt": "^3.0.0",
    "trim": "0.0.1",
    "util": "^0.10.3",
    "validator": "^6.2.0",
    "xlsx": "^0.8.0",
    "connect-multiparty": "^2.0.0"
  },
  "devDependencies": {
    "grunt": "~0.4.4",
    "grunt-autoprefixer": "~0.7.2",
    "grunt-wiredep": "~1.8.0",
    "grunt-concurrent": "~0.5.0",
    "grunt-contrib-clean": "~0.5.0",
    "grunt-contrib-concat": "~0.4.0",
    "grunt-contrib-copy": "~0.5.0",
    "grunt-contrib-cssmin": "~0.9.0",
    "grunt-contrib-htmlmin": "~0.2.0",
    "grunt-contrib-imagemin": "^1.0.0",
    "grunt-contrib-jshint": "~0.10.0",
    "grunt-contrib-uglify": "~0.4.0",
    "grunt-contrib-watch": "~0.6.1",
    "karma-babel-preprocessor": "^5.2.1",
    "grunt-babel": "~5.0.0",
    "grunt-google-cdn": "~0.4.0",
    "grunt-newer": "~0.7.0",
    "grunt-ng-annotate": "^0.2.3",
    "grunt-rev": "~0.1.0",
    "grunt-svgmin": "~0.4.0",
    "grunt-usemin": "~2.1.1",
    "grunt-env": "~0.4.1",
    "grunt-node-inspector": "~0.1.5",
    "grunt-nodemon": "~0.2.0",
    "grunt-angular-templates": "^0.5.4",
    "grunt-dom-munger": "^3.4.0",
    "grunt-protractor-runner": "^1.1.0",
    "grunt-injector": "~0.5.4",
    "grunt-karma": "~0.8.2",
    "grunt-build-control": "~0.4.0",
    "grunt-mocha-test": "~0.10.2",
    "grunt-contrib-sass": "^0.7.3",
    "jit-grunt": "^0.5.0",
    "time-grunt": "~0.3.1",
    "grunt-express-server": "~0.4.17",
    "grunt-open": "~0.2.3",
    "open": "~0.0.4",
    "jshint-stylish": "~0.1.5",
    "connect-livereload": "~0.4.0",
    "karma-ng-scenario": "~0.1.0",
    "karma-firefox-launcher": "~0.1.3",
    "karma-script-launcher": "~0.1.0",
    "karma-html2js-preprocessor": "~0.1.0",
    "karma-ng-jade2js-preprocessor": "^0.1.2",
    "karma-jasmine": "~0.1.5",
    "karma-chrome-launcher": "~0.1.3",
    "requirejs": "~2.1.11",
    "karma-requirejs": "~0.2.1",
    "karma-coffee-preprocessor": "~0.2.1",
    "karma-jade-preprocessor": "0.0.11",
    "karma-phantomjs-launcher": "~0.1.4",
    "karma": "~0.12.9",
    "karma-ng-html2js-preprocessor": "~0.1.0",
    "supertest": "~0.11.0",
    "should": "~3.3.1"
  },
  "engines": {
    "node": ">=0.10.0"
  },
  "scripts": {
    "start": "node server/app.js",
    "test": "grunt test",
    "update-webdriver": "node node_modules/grunt-protractor-runner/node_modules/protractor/bin/webdriver-manager update"
  },
  "private": true
}

但是我的docker容器无法启动,因为它在npm install中找到了错误代码。

1 个答案:

答案 0 :(得分:1)

尝试

RUN npm install || true

这应该确保步骤应该始终成功