DOCKER:npm ERR!缺少脚本:开始

时间:2020-10-28 09:43:32

标签: node.js docker npm

每次在终端机上输入docker-compose up时,都会出现此错误:

blogapp | npm ERR! missing script: start
blogapp | 
blogapp | npm ERR! A complete log of this run can be found in:
blogapp | npm ERR!     /root/.npm/_logs/2020-10-28T08_54_29_180Z-debug.log
blogapp exited with code 1

在退出应用程序之前,我多次获得它。 这是我的package.json:

    "name": "blogapp",
    "version": "1.0.0",
    "description": "blog app",
    "main": "app.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "node app.js"
    },
    "author": "me",
    "license": "ISC",
    "dependencies": {
        "@material/button": "^7.0.0",
        "ejs": "^3.1.5",
        "express": "^4.17.1",
        "mongoose": "^5.10.9",
        "morgan": "^1.10.0"
    }
}

请帮助我找到这个问题的根源。 如果需要我分享其他文件或信息,请告诉我。

-x-

编辑:

Dockerfile:

FROM node:latest

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

EXPOSE 3000

CMD ["npm", "start"]

和docker-compose.yml:

version: '3'
services:
    app:
        container_name: blogapp
        restart: always
        build: .
        ports:
            - '80:3000'
        links:
            - mongo
    mongo:
        container_name: mongoDB
        image: mongo
        ports:
            - '27017:27017'

此外,我不知道如何访问调试日志(初次使用),因此也请帮我。

1 个答案:

答案 0 :(得分:0)

请确保您设置了正确的启动文件,并确保您没有多个“启动”脚本。如果这样做没有帮助,请在/root/.npm/_logs/2020-10-28T08_54_29_180Z-debug.log

下发布给定的日志