Here is my project struture
.
├── README.md
├── docker-compose.yml
└── frontend
├── Dockerfile
├── README.md
├── build
├── package.json
├── yarn.lock
└── ...
Docker-compose.yml
version: '3.7'
services:
frontend:
build:
context: frontend
dockerfile: Dockerfile
volumes:
- '.:/app'
- '/app/node_modules'
ports:
- 3000:3000
Dockerfile
FROM node:14-alpine
WORKDIR /app
COPY ./package.json /app/package.json
RUN yarn install --no-lockfile
COPY . .
CMD ["yarn", "start"]
If i build container using docker, it works fine
But docker-compose up --build
always returns
Attaching to book-marketplace_frontend_1
frontend_1 | yarn run v1.22.15
frontend_1 | error Couldn't find a package.json file in "/app"
frontend_1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
book-marketplace_frontend_1 exited with code 1
it's weird that docker-compose can still run yarn install ( which needs package.json) but can not locate it later. Hope someone can help me
Because you are already in workdir app
as you earlier defined as WORKDIR
. So change the line to:
COPY ./package.json /package.json