首页 > 解决方案 > npm 错误!在码头工人撰写

问题描述

我是 docker 新手,我正在尝试从docker-compose.yml文件构建容器

version: '3.0'

volumes: 
  mongodb:
  esdb:
    driver: local

services: 
  app:
    build: ./
    command: npm run dev
    container_name: beez-backend
    networks:
      - custom      
    volumes:
      - ./:/beez-backend/
    ports:
      - "3030:3030"
      - "9229:9229"
    external_links:  
      - mongo 
    depends_on:
      - mongo
    env_file:
      ./dev.env

  # MongoDB image config - this container will exposed as external so other container will use it 
  mongo:
    image: mongo
    container_name: beez-backend-mongo
    ports: 
    - "27036:27017"
    volumes:
      - mongodb:/data/db 
    networks:
      - custom

networks:
  custom:
    external: true 

和我的Dockerfile

FROM node:dubnium-alpine

LABEL maintainer="XXX"


RUN mkdir -p /beez-backend

RUN npm install nodemon -g

WORKDIR /beez-backend


COPY package.json /beez-backend
RUN npm install 

COPY . /beez-backend

EXPOSE 3030
EXPOSE 9229

CMD ["npm","start"]

package.json 依赖项 -

{
  "name": "XXX",
  "description": "XXX",
  "version": "0.0.0",
  "homepage": "",
  "main": "src",
  "keywords": [
    "feathers",
    "beez"
  ],
  "author": {
    "name": "X",
    "email": "X"
  },
  "contributors": [],
  "bugs": {},
  "directories": {
    "lib": "src",
    "test": "test/"
  },
  "engines": {
    "node": "^11.0.0",
    "npm": ">= 3.0.0"
  },
  "scripts": {
    "test": "npm run eslint && NODE_ENV= npm run mocha",
    "eslint": "eslint src/. test/. --config .eslintrc.json",
    "dev": "nodemon -L --delay 2 --inspect=0.0.0.0:9229 src/",
    "start": "node src/",
    "mocha": "mocha test/ --recursive --exit"
  },
  "dependencies": {
    "@feathersjs/authentication": "^4.5.2",
    "@feathersjs/authentication-local": "^4.5.2",
    "@feathersjs/authentication-oauth": "^4.5.2",
    "@feathersjs/configuration": "^4.5.2",
    "@feathersjs/errors": "^4.5.2",
    "@feathersjs/express": "^4.5.2",
    "@feathersjs/feathers": "^4.5.2",
    "@feathersjs/socketio": "^4.5.2",
    "axios": "^0.19.2",
    "compression": "^1.7.4",
    "cors": "^2.8.5",
    "cron": "^1.7.2",
    "exceljs": "^3.8.1",
    "feathers-authentication-hooks": "^1.0.0",
    "feathers-authentication-management": "^2.0.1",
    "feathers-hooks-common": "^4.20.7",
    "feathers-mailer": "^3.0.1",
    "feathers-mongoose": "^8.1.0",
    "feathers-populate-hook": "^0.5.3",
    "feathers-swagger": "^1.1.1",
    "firebase-admin": "^8.6.0",
    "form-data": "^2.5.1",
    "helmet": "^3.21.3",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "mongodb-core": "^3.2.7",
    "mongoosastic": "^4.5.1",
    "mongoose": "^5.9.3",
    "multer": "^1.4.2",
    "multer-google-storage": "^1.3.0",
    "nodemailer-sendgrid": "^1.0.3",
    "nodemailer-sendgrid-transport": "^0.2.0",
    "nodemailer-smtp-transport": "^2.7.4",
    "npm": "^6.14.2",
    "pug": "^2.0.4",
    "serve-favicon": "^2.5.0",
    "validator": "^11.1.0",
    "winston": "^3.2.1"
  },
  "devDependencies": {
    "eslint": "^6.5.1",
    "mocha": "^6.2.1",
    "nodemon": "^1.19.4",
    "request": "^2.88.2",
    "request-promise": "^4.2.5"
  }
}

它会正确执行这些步骤,直到步骤 7/11 是RUN npm install. 这是给出错误:

npm ERR! Unexpected end of JSON input while parsing near /..UyIRBcPKVK9LxycWnlezO'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-05-21T17_48_59_909Z-debug.log
ERROR: Service 'app' failed to build:
       The command '/bin/sh -c npm install' returned a non-zero code: 1 

我尝试了npm cache clean --force并运行docker-compose up,但它没有改变。我还尝试在 DockerfileRUN npm cache clean之前添加该行RUN npm install,但它仍然不起作用。Dockerfile 和 docker-compose.yml 文件都在同一个目录中。

标签: dockernpmdocker-compose

解决方案


尝试以下步骤:

  1. $ npm cache clean --force 或 $npm cache verify

  2. $ npm install -g @angular/cli@latest

  3. $ npm install --save-dev @angular/cli@latest

  4. 删除 node_modules

  5. $ npm install


推荐阅读