Yarn Workspace dist folder not found in named volumes/anon volumes

As the name of the title, I am trying to run the container using docker compose up but will failed since it couldn’t find the dist folder of one of the workpace packages.

folder structure:

- packages
 |- package-a
- package.json

package.json

{
  "workspaces": {
        "packages": [
            "packages/*"
        ]
    },
}

Dockerfile:

FROM node:12.19.0

RUN mkdir /src

WORKDIR /src

RUN npm install -g typescript 

COPY . .

RUN yarn install

RUN yarn workspace-packages

CMD ["yarn", "dev"]

Docker Comose file:

version: '3.9'

networks:
  public:

services:
  api:
    build: .
    container_name: api
    volumes:
      - .:/src
      - /src/node_modules
    ports:
      - "8443:8443"
    networks:
      - public

with this settings, when running docker compose up -V it will log an error of cannot find package-a dist folder.

When checking inside the container node_modules and check package-a folder only some fie and folder exist

- package.json
- src
- tsconfig.json

but when I try to change the docker-compose.yml to:

version: '3.9'

networks:
  public:

services:
  api:
    build: .
    container_name: api
    command: ping google.com
    volumes:
      - /src/node_modules
    ports:
      - "8443:8443"
    networks:
      - public

and checking again inside node_modules package-a folder i can find all files including the dist folder:

- dist
- node_modules
- package.json
- src
- tsconfig.json

is there reason why it is showing like this? or I am missing something in the setting?

With this

you mounted your compose project root to /src inside the container. If something was installed under /src during docker build, that is hidden by the bind mount. It will not merge your folders, it will completely override the content in the container.

yeah, i think I misunderstood how yarn workspace works on how it is installed. I have to include the packages folder as a anon volumes as well since all files are in there, since I am using the root directory in bind mounting it and it has packages folder in there as well. It got overwritten by the bind volumes.

So in the docker compose:

version: '3.9'

networks:
  public:

services:
  api:
    build: .
    container_name: api
    volumes:
      - .:/src
      - /src/node_modules
      - /src/packages
    ports:
      - "8443:8443"
    networks:
      - public

Thanks for the info @rimelek.