运行docker-compose时找不到服务package.json

nbysray5  于 2023-06-05  发布在  Docker
关注(0)|答案(2)|浏览(255)

我正在工作空间内构建一个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运行的上下文有关。
以下是我的工作空间结构:

├── agent-portal-service
├── data
├── docker-compose.yml
└── entity-service

我的docker-compose.yml

version: "3"

services:
  agent_portal_service:
    working_dir: /agent-portal-service
    container_name: agent_portal_service
    image: node:16
    volumes:
      - /agent-workspace:/agent-portal-service
    ports:
      - 3100:3100
    command: npm run start:debug
    tty: true

  entity_service:
    working_dir: /entity-service
    container_name: entity_service
    image: node:16
    volumes:
      - /agent-workspace:/entity-service
    ports:
      - 3101:3101
    command: npm run start:debug
    tty: true
    depends_on:
      - mongodb

  mongodb:
    container_name: mongodb
    image: mongo:4.4.6
    ports:
      - 27017:27017
    volumes:
      - ./data/db:/data/db
    command: mongod --port 27017
    restart: always

我希望能够成功运行agent_portal_serviceentity_service容器

l0oc07j2

l0oc07j21#

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

entity_service:
    working_dir: /entity-service
    volumes:
      - /agent-workspace:/entity-service
    command: npm run start:debug

在volumes部分中将/agent-workspaceMap到/entity-service。您还将工作目录设置为/entity-service。实际上,您的工作目录是主机上的/agent-workspace/agent-workspace目录中没有package.json文件,因此npm命令失败。
为了解决这个问题,我将/agent-workspace/entity-serviceMap到/entity-service。这样,容器内的/entity-service目录中将有一个package.json文件。
就像这样

volumes:
  - /agent-workspace/entity-service:/entity-service
t98cgbkg

t98cgbkg2#

你用

image: node:16

通常你需要创建客户的Dockerfile,并在你的docker镜像中复制代码+编译代码

相关问题