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:
├── agent-portal-service
├── data
├── docker-compose.yml
└── entity-service
My 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
I am expecting to be able to run the agent_portal_service
and entity_service
containers successfully
2
Answers
you use
usually you need to create customer Dockerfile and and copy code inside your docker image + compile code
The important parts of your entity-service definition look like this
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 nopackage.json
file in the/agent-workspace
directory, so yournpm
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