skip to Main Content

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


  1. you use

    image: node:16
    

    usually you need to create customer Dockerfile and and copy code inside your docker image + compile code

    Login or Signup to reply.
  2. The important parts of your entity-service definition look like this

      entity_service:
        working_dir: /entity-service
        volumes:
          - /agent-workspace:/entity-service
        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

    volumes:
      - /agent-workspace/entity-service:/entity-service
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search