Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose, failed to solve: rpc error: code = Unknown desc = failed to compute cache key: "/app/package.json" not found: not found

I have a problem with pathways docker-compose, when I try build project with only docker build, it works great, but I mustn't use docker build, I have to use docker-compose. When I use docker-compose it returns 2 ERRORS at step 3/5 => ERROR [3/5] COPY /app/package.json . and at step 5/5 => ERROR [5/5] COPY /app .:

PS C:\Users\mamba\Desktop\project-practice> docker-compose -f docker/docker-compose.yml up -d
[+] Building 1.4s (9/9) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                          0.1s 
 => => transferring dockerfile: 31B                                                                                                                           0.0s 
 => [internal] load .dockerignore                                                                                                                             0.1s 
 => => transferring context: 34B                                                                                                                              0.0s 
 => [internal] load metadata for docker.io/library/node:latest                                                                                                1.0s 
 => [1/5] FROM docker.io/library/node@sha256:c3356b2b11ad643852a321308c15d70ca2bc106e40d3ffe7a4879d3588a9d479                                                 0.0s 
 => [internal] load build context                                                                                                                             0.1s 
 => => transferring context: 2B                                                                                                                               0.0s 
 => CACHED [2/5] WORKDIR /app                                                                                                                                 0.0s 
 => ERROR [3/5] COPY /app/package.json .                                                                                                                      0.0s 
 => CACHED [4/5] RUN npm install                                                                                                                              0.0s 
 => ERROR [5/5] COPY /app .                                                                                                                                   0.0s 
------
 > [3/5] COPY /app/package.json .:
------
------
 > [5/5] COPY /app .:
------
failed to solve: rpc error: code = Unknown desc = failed to compute cache key: "/app/package.json" not found: not found

this is my project structure http://skrinshoter.ru/s/080721/upY64zwf

this is my Dockerfile

FROM node
WORKDIR /app
COPY /app/package.json .
RUN npm install
COPY /app .
EXPOSE 3000
CMD ["npm", "start"]

this is my docker-compose.yml

version: "3.8"
services: 
    react-app:
        working_dir: /app
        build: 
            dockerfile: Dockerfile
        ports: 
            - "3000:3000"
        volumes: 
            - ./app/src:/app/src
        environment: 
            - CHOKIDAR_USEPOLLING=true
        # env_file: 
        #     - ./docker/.env

If I move docker-compose.yml upper in structure of files to project-practice, it works great, it builds and server starts, but I have to keep structure of folders and files like this.

|-project-practice
|-app
|  |...
|-docker
   |...
like image 607
f1x0z Avatar asked Jul 08 '21 20:07

f1x0z


1 Answers

Looks like you mounting volumes wrong. Change your docker-compose configuration from:

build: 
     dockerfile: Dockerfile
volumes:
     - ./app/src:/app/src     

You mounting only the SRC folder, but you need files outside of it. Also you need to add context to your docker file

to:

build: 
     context: ../
     dockerfile: /docker/Dockerfile
volumes:
     - ../app:/app

The path should be relative to a docker-compose file location.

Also you need to modify Dockerfile:

FROM node
WORKDIR /app
COPY /app/package.json .
RUN npm install
COPY /app .
EXPOSE 3000
CMD ["npm", "start"]
like image 90
Rmik Avatar answered Oct 21 '22 19:10

Rmik