docker-compose, failed to solve: rpc error: code = Unknown desc = failed to compute cache key: "/app/package.json" not found: not found
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"]
Related videos on Youtube
f1x0z
Updated on June 05, 2022Comments
-
f1x0z 7 monthsI have a problem with pathways
docker-compose, when I try build project with onlydocker build, it works great, but I mustn't usedocker build, I have to usedocker-compose. When I usedocker-composeit 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 foundthis 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/.envIf 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 over 1 yearI tryed do as you say and it not helps :( what am i do wrong? -
f1x0z over 1 yearI tryed to do as you say, but it still same problems :(( -
f1x0z over 1 yearonly this changed nowfailed to solve: rpc error: code = Unknown desc = failed to compute cache key: "/app" not found: not found -
f1x0z over 1 yearbut=> ERROR [3/5] COPY /app/package.json .and=> ERROR [5/5] COPY /app .not changed :( -
Rmik over 1 yearYep, got it. You need to modify Dockerfile.COPY ../app/package.json .andCOPY ../app . -
f1x0z over 1 yearanyway, :((( not working, same thing(=> ERROR [3/5] COPY ../app/package.json .and=> ERROR [5/5] COPY ../app .andfailed to solve: rpc error: code = Unknown desc = failed to compute cache key: "/app/package.json" not found: not found:(((((( -
David Maze over 1 yearPaths in theCOPYcommand need to be relative to thebuild: { context: }directory, and can't start with... See also How to include files outside of Docker's build context?. -
Muhammad Irfan Aslam 10 monthsi also faced issue but in my case node_module folder was present and I just delete it and it worked perfectly -
Muhammad Irfan Aslam 10 monthsi 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