我是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
,但是它没有改变。我还尝试在Dockerfile中的RUN npm cache clean
之前添加行RUN npm install
,但仍然无法正常工作。 Dockerfile和docker-compose.yml文件都在同一目录中。
答案 0 :(得分:0)
尝试以下步骤:
$ npm cache clean --force
要么
$ npm cache verify
$ npm install -g @angular/cli@latest
$ npm install --save-dev @angular/cli@latest
删除node_modules
运行$ npm install