Check File Existence
Ensure that the yarn.lock file exists in the context of your Docker build. The Docker build context is the directory from which you run the docker build command. If the yarn.lock file is not present in the same directory as your Dockerfile, the build will fail.
Verify the presence of yarn.lock: ls -l ./yarn.lock
Correct Build Context
Make sure you are running the docker build command from the correct directory where your Dockerfile and yarn.lock file are located. For example, if your directory structure looks like this:
/my-app
├── Dockerfile
├── package.json
├── yarn.lock
└── src
You should run the following command from the /my-app directory: docker build -t your_image_name .
Update Dockerfile : If you have confirmed that the yarn.lock file exists and you are in the correct directory, ensure that your Dockerfile is correctly set up to copy the file. Your Dockerfile should include the following lines:
COPY ./package.json .
COPY ./yarn.lock .
Clean Docker Build Cache
Sometimes, Docker's build cache can cause issues. You can try building the image without using the cache:
docker build --no-cache -t your_image_name .
Verify Docker Installation
Ensure that your Docker installation is functioning correctly. You can check the Docker version and status:
docker --version
docker info
Check for Docker Daemon Issues
If the problem persists, ensure that the Docker daemon is running correctly. If you are on a Linux system, you can check the status with:
sudo systemctl status docker
FROM node:16.17.0-alpine as builder WORKDIR /app COPY ./package.json . COPY ./yarn.lock . RUN yarn install COPY . . ARG TMDB_V3_API_KEY ENV VITE_APP_TMDB_V3_API_KEY=${TMDB_V3_API_KEY} ENV VITE_APP_API_ENDPOINT_URL="https://api.themoviedb.org/3" RUN yarn build
FROM nginx:stable-alpine WORKDIR /usr/share/nginx/html RUN rm -rf ./* COPY --from=builder /app/dist . EXPOSE 80 ENTRYPOINT ["nginx", "-g", "daemon off;"]