我正在工作空间内构建一个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_service
和entity_service
容器
2条答案
按热度按时间l0oc07j21#
实体服务定义的重要部分如下所示
在volumes部分中将
/agent-workspace
Map到/entity-service
。您还将工作目录设置为/entity-service
。实际上,您的工作目录是主机上的/agent-workspace
。/agent-workspace
目录中没有package.json
文件,因此npm
命令失败。为了解决这个问题,我将
/agent-workspace/entity-service
Map到/entity-service
。这样,容器内的/entity-service
目录中将有一个package.json文件。就像这样
t98cgbkg2#
你用
通常你需要创建客户的Dockerfile,并在你的docker镜像中复制代码+编译代码