简体   繁体   English

Docker 在 nodejs 微服务应用程序中组合卷

[英]Docker compose volumes in nodejs microservices application

When make volumes in docker-compose.yml and run docker-compose up and in "yarn run" step, it says (error Couldn't find a package.json file in "/usr/src/app")当在 docker-compose.yml 中制作卷并运行 docker-compose up 并在“yarn run”步骤中,它说(错误在“/usr/src/app”中找不到 package.json 文件)

my Dockerfile我的 Dockerfile

FROM node:12
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json .
COPY yarn.lock .
RUN yarn
COPY . .
CMD [ "yarn", "watch" ]

docker-compose.yml docker-compose.yml

version: "3"
services:
    listings-service:
        build: ./listings-service
        volumes:
            - ./listings-service:/usr/src/app

package.json包.json

{
  "name": "listings-service",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "watch": "babel-watch -L ./index.js"
  },
  "devDependencies": {
    "babel-watch": "^7.0.0",
    "nodemon": "^2.0.2"
  },
  "dependencies": {
    "@babel/core": "^7.9.0",
    "@babel/polyfill": "^7.8.7",
    "@babel/preset-env": "^7.9.0",
    "babel-plugin-module-resolver": "^4.0.0",
    "core-js": "3"
  }
}

why do you need the volume here?为什么这里需要音量? your docker files compy all the files in and place them inside the docker image.您的 docker 文件会编译所有文件并将它们放入 docker 映像中。 In addition, running yarn will install dependencies and place them in /usr/src/app .此外,运行yarn将安装依赖项并将它们放在/usr/src/app

Adding the volume on the docker-compose ==> all files from the docker image will be removed and placed with the files inside the local path ./listings-service在 docker-compose 上添加卷 ==> ./listings-service镜像中的所有文件将被删除并与本地路径中的文件一起放置./listings-service

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM