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
This is because that volumes in docker-compose.yml is path relative to docker-compose.yml.
You can try volumes to specify path below:
Hey this is because when you build your image the context is
docker/node
so when you try toCOPY package.json
he isn’t found insidedocker/node
You should be able to fix this by using: