无法在运行docker-compose时找到services package.json。

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

Can't find services package.json when running docker-compose

问题

我正在在一个工作空间内构建一个 docker-compose.yml 文件,但是当我尝试运行 docker-compose 时,由于以下错误 ENOENT: no such file or directory, open '/entity-service/package.json',我的服务无法启动,同时,在尝试启动 agent-portal-service 容器时也出现了相同的错误,但是错误发生在这个目录中 /agent-portal-service/package.json。但我的项目确实有一个 package.json 文件,我认为这与 docker-compose 运行的上下文有关。

这是我的工作空间结构:

  1. ├── agent-portal-service
  2. ├── data
  3. ├── docker-compose.yml
  4. └── entity-service

我的 docker-compose.yml 文件如下:

  1. version: "3"
  2. services:
  3. agent_portal_service:
  4. working_dir: /agent-portal-service
  5. container_name: agent_portal_service
  6. image: node:16
  7. volumes:
  8. - /agent-workspace:/agent-portal-service
  9. ports:
  10. - 3100:3100
  11. command: npm run start:debug
  12. tty: true
  13. entity_service:
  14. working_dir: /entity-service
  15. container_name: entity_service
  16. image: node:16
  17. volumes:
  18. - /agent-workspace:/entity-service
  19. ports:
  20. - 3101:3101
  21. command: npm run start:debug
  22. tty: true
  23. depends_on:
  24. - mongodb
  25. mongodb:
  26. container_name: mongodb
  27. image: mongo:4.4.6
  28. ports:
  29. - 27017:27017
  30. volumes:
  31. - ./data/db:/data/db
  32. command: mongod --port 27017
  33. restart: always

我期望能够成功运行 agent_portal_serviceentity_service 容器。

英文:

I am building a docker-compose.yml file inside a workspace, but when I try to run docker-compose, I can't start my services because of the following error ENOENT: no such file or directory, open '/entity-service/package.json' the same error happens when trying to start the agent-portal-service container as well but the error happens in this directory /agent-portal-service/package.json. But my projects indeed have a package.json file, I think that this is related to the context that docker-compose is running.

Here is my workspace structure:

  1. ├── agent-portal-service
  2. ├── data
  3. ├── docker-compose.yml
  4. └── entity-service

My docker-compose.yml:

  1. version: "3"
  2. services:
  3. agent_portal_service:
  4. working_dir: /agent-portal-service
  5. container_name: agent_portal_service
  6. image: node:16
  7. volumes:
  8. - /agent-workspace:/agent-portal-service
  9. ports:
  10. - 3100:3100
  11. command: npm run start:debug
  12. tty: true
  13. entity_service:
  14. working_dir: /entity-service
  15. container_name: entity_service
  16. image: node:16
  17. volumes:
  18. - /agent-workspace:/entity-service
  19. ports:
  20. - 3101:3101
  21. command: npm run start:debug
  22. tty: true
  23. depends_on:
  24. - mongodb
  25. mongodb:
  26. container_name: mongodb
  27. image: mongo:4.4.6
  28. ports:
  29. - 27017:27017
  30. volumes:
  31. - ./data/db:/data/db
  32. command: mongod --port 27017
  33. restart: always

I am expecting to be able to run the agent_portal_service and entity_service containers successfully

答案1

得分: 1

您实体服务定义的重要部分如下所示:

  1. entity_service:
  2. working_dir: /entity-service
  3. volumes:
  4. - /agent-workspace:/entity-service
  5. command: npm run start:debug

您在卷部分将 /agent-workspace 映射到 /entity-service。您还将工作目录设置为 /entity-service。实际上,您的工作目录是在主机机器上的 /agent-workspace/agent-workspace 目录中没有 package.json 文件,因此您的 npm 命令失败。

为了解决这个问题,我建议将 /agent-workspace/entity-service 映射到 /entity-service,这样您容器内的 /entity-service 目录将包含一个 package.json 文件。

像这样:

  1. volumes:
  2. - /agent-workspace/entity-service:/entity-service
英文:

The important parts of your entity-service definition look like this

  1. entity_service:
  2. working_dir: /entity-service
  3. volumes:
  4. - /agent-workspace:/entity-service
  5. command: npm run start:debug

You map /agent-workspace to /entity-service in the volumes section. You also set your working directory to /entity-service. In effect, your working directory is /agent-workspace on your host machine. There's no package.json file in the /agent-workspace directory, so your npm command fails.

To fix it, I'd map /agent-workspace/entity-service to /entity-service instead. That way, you'll have a package.json file in your /entity-service directory inside the container.

Like this

  1. volumes:
  2. - /agent-workspace/entity-service:/entity-service

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

发表评论

匿名网友

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

确定