Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker compose fail to start container in monorepo environment

I have a PNPM workspace environment. I try to build one of my package using docker compose.

To do so, I have the following script in package.json file (in root folder):
"cluster:start": "pnpm exec ./docker/scripts/start-cluster.sh"

This is the ./docker/scripts/start-cluster.sh file:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#!/bin/bash

docker-compose up -d

This is my docker-compose.yaml file:

version: '3.8'

services:
frontend:
    container_name: frontend
    build:
        context: ./docker
        dockerfile: Dockerfile.frontend-dev
    env_file:
        - ./apps/frontend/.env.development
    ports:
        - 8080:8080
    restart: always
    networks:
        - dashboard_network
networks:
    dashboard_network:
        driver: bridge

And this is my ./docker/Dockerfile.frontend-dev file:

FROM node:16

RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm

WORKDIR /dashboard

COPY ../package.json ./
COPY ../apps/frontend/package.json ./apps/frontend/

RUN pnpm install

COPY ../ ./

CMD ["pnpm", "--filter", "frontend", "start"]

So when I run on root folder pnpm cluster:start I get an error:

=> ERROR [dashboard-frontend 4/7] COPY ../package.json ./                                                                                                          0.0s
 => ERROR [dashboard-frontend 5/7] COPY ../apps/frontend/package.json ./apps/frontend/                                                                              0.0s
------
 > [dashboard-frontend 4/7] COPY ../package.json ./:
------
------
 > [dashboard-frontend 5/7] COPY ../apps/frontend/package.json ./apps/frontend/:
------
failed to solve: failed to compute cache key: "/apps/frontend/package.json" not found: not found

Could anyone tell why?

This is the path to this error file: ROOT_FOLDER/apps/frontend/package.json

>Solution :

Short answer to "why": docker context.

This command is wrong:

COPY ../package.json ./

You cannot get "out" of the docker build context.

In your docker-compose.yml you define a context. That is a folder. When the build starts, the contents of that folder (with exceptions defined in .dockerignore) are sent to the docker daemon. And that is the set of file that your COPY commands can see. Nothing else. So the COPY does not work in your current folder, but on a copy of that folder that was sent to the docker daemon.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading