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

18,547

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"]
Share:
18,547

Related videos on Youtube

f1x0z
Author by

f1x0z

Updated on June 05, 2022

Comments

  • f1x0z
    f1x0z 7 months

    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/[email protected]: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
       |...
    
  • f1x0z
    f1x0z over 1 year
    I tryed do as you say and it not helps :( what am i do wrong?
  • f1x0z
    f1x0z over 1 year
    I tryed to do as you say, but it still same problems :((
  • f1x0z
    f1x0z over 1 year
    only this changed now failed to solve: rpc error: code = Unknown desc = failed to compute cache key: "/app" not found: not found
  • f1x0z
    f1x0z over 1 year
    but => ERROR [3/5] COPY /app/package.json . and => ERROR [5/5] COPY /app . not changed :(
  • Rmik
    Rmik over 1 year
    Yep, got it. You need to modify Dockerfile. COPY ../app/package.json . and COPY ../app .
  • f1x0z
    f1x0z over 1 year
    anyway, :((( not working, same thing( => ERROR [3/5] COPY ../app/package.json . and => ERROR [5/5] COPY ../app . and failed to solve: rpc error: code = Unknown desc = failed to compute cache key: "/app/package.json" not found: not found :((((((
  • David Maze
    David Maze over 1 year
    Paths in the COPY command need to be relative to the build: { context: } directory, and can't start with ... See also How to include files outside of Docker's build context?.
  • Muhammad Irfan Aslam
    Muhammad Irfan Aslam 10 months
    i also faced issue but in my case node_module folder was present and I just delete it and it worked perfectly
  • Muhammad Irfan Aslam
    Muhammad Irfan Aslam 10 months
    i also faced issue but in my case node_module folder was present and I just delete it and it worked perfectly and hopefully I will help you too

Related