skip to Main Content

I have project’s folder "fruits". And i wanted to dockerize my project with node.

But get the error when i execute "docker-compose up" :

failed to solve: failed to compute cache key: "/package.json" not found

My folders is

  • docker
    • node
      • Dockerfile
  • node_modules
  • public
  • src
  • package.json
  • package-lock.json
  • docker-compose.yaml
  • etc

My docker-compose.yaml file is :

version: "3"
services:
  node:
    build: docker/node
    volumes:
      - ./:/app
    ports:
      - 5000:3000

My Dockerfile is :

FROM node:19-alpine

WORKDIR /app


COPY package.json ./

RUN npm install
COPY . .

EXPOSE 3000


CMD ["npm","start"]

2

Answers


  1. This is because that volumes in docker-compose.yml is path relative to docker-compose.yml.

    You can try volumes to specify path below:

    version: "3"
    services:
      node:
        build: docker/node
        volumes:
          - ../../:/app
        ports:
          - 5000:3000
    
    
    Login or Signup to reply.
  2. Hey this is because when you build your image the context is docker/node so when you try to COPY package.json he isn’t found inside docker/node

    You should be able to fix this by using:

    version: "3"
    services:
      node:
        build:
          context: .
          dockerfile: ./docker/node/Dockerfile
        volumes:
          - ./:/app
        ports:
          - 5000:3000
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search