npm ERR! 缺少脚本: start 在运行 docker compose up 时

huangapple go评论78阅读模式
英文:

npm ERR! missing script: start when running docker compose up

问题

我正在尝试在Docker容器上运行Node.js应用程序与MongoDB。然而,每次运行docker compose up命令时,我都会收到以下错误:

>npm ERR! missing script: start

这是我的Dockerfile:

FROM node:8.11-slim
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 5500

CMD ["npm","start"]


这是我的docker-compose.yml文件:

version: '3'
services:
app:
container_name: ians-mongo
restart: always
build: ./vidly
ports:
- '5500:5500'
external_links:
- mongo

mongo:
container_name: mongo
image: mongo
volumes:
- ./data:/data/db
ports:
- '27012:27017'

mongo-express:
container_name: mongo-express
image: mongo-express
ports:
- '8083:8081'


这是我的package.json:

{
"name": "vidly",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "nodemon index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"config": "^3.3.9",
"debug": "^4.3.4",
"express": "^4.18.2",
"helmet": "^7.0.0",
"joi": "^17.9.2",
"morgan": "^1.10.0"
},
"devDependencies": {
"nodemon": "^2.0.22"
}
}


这是我的文件夹结构的屏幕截图:[![enter image description here][1]][1]

我想知道是否与Dockerfile无法找到package.json文件或yml文件中的build属性的值可能不正确有关。
[1]: https://i.stack.imgur.com/4mLw3.png
英文:

I am trying to run mongodb with a Node.js app on a docker container. However, every time I run the docker compose up command, I receive the following error:

>npm ERR! missing script: start

Here is my Dockerfile:

FROM node:8.11-slim
WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 5500

CMD ["npm","start"]

Here is my docker-compose.yml file:

version: '3'
services:
  app:
    container_name: ians-mongo
    restart: always
    build: ./vidly
    ports:
      - '5500:5500'
    external_links:
      - mongo

  mongo:
    container_name: mongo
    image: mongo
    volumes:
      - ./data:/data/db
    ports:
      - '27012:27017'

  mongo-express:
    container_name: mongo-express
    image: mongo-express
    ports:
      - '8083:8081'

And here is my package.json:

{
  "name": "vidly",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "config": "^3.3.9",
    "debug": "^4.3.4",
    "express": "^4.18.2",
    "helmet": "^7.0.0",
    "joi": "^17.9.2",
    "morgan": "^1.10.0"
  },
  "devDependencies": {
    "nodemon": "^2.0.22"
  }
}

Here is a screenshot of my folder structure:

npm ERR! 缺少脚本: start 在运行 docker compose up 时

I'm wondering if it has something do with the dockerfile not being able to find the package.json file, or possibly the value for the build property in the yml file being incorrect.

答案1

得分: 1

你应该在docker-compose文件中更改应用程序的构建语句。它当前正在查看一个名为"vidly"的子目录,而这在你的屏幕截图中是不存在的。你可以添加一个dockerfile语句,以确保正确的Docker文件被使用。

version: '3'
services:
  app:
    container_name: ians-mongo
    restart: always
    build: 
      context: .
      dockerfile: ./Dockerfile
    ports:
      - '5500:5500'
    external_links:
      - mongo
英文:

You should change the build statement for your app in the docker-compose file. It is currently looking at a "vidly" subdirectory, that doesn't exist in your screenshot. You could add a dockerfile statement which would make sure the correct dockerfile is seen.

version: '3'
services:
  app:
    container_name: ians-mongo
    restart: always
    build: 
      context: .
      dockerfile: ./Dockerfile
    ports:
      - '5500:5500'
    external_links:
      - mongo

</details>



huangapple
  • 本文由 发表于 2023年6月16日 01:48:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76484282.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定