Problem to create vite project with docker
I’m trying to create a Vite project with Docker, but I’m running into an issue when I attempt to build the container using docker-compose up --build -d
.
Docker files
Dockerfile
FROM node:23-alpine
WORKDIR /app
RUN npm install -g create-vite
RUN npm create vite@latest . --template vanilla --yes
RUN npm install
EXPOSE 3000
CMD ["npm", "run", "dev"]
docker compose
version: '3'
services:
vite:
build: .
volumes:
- ./:/app
ports:
- "3000:3000"
container_name: "vite-project"
Error
Building vite
[+] Building 0.5s (8/8) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 217B 0.0s
=> [internal] load metadata for docker.io/library/node:23-alpine 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/5] FROM docker.io/library/node:23-alpine 0.0s
=> CACHED [2/5] WORKDIR /app 0.0s
=> CACHED [3/5] RUN npm install -g create-vite 0.0s
=> CACHED [4/5] RUN npm create vite@latest . --template vanilla --yes 0.0s
=> ERROR [5/5] RUN npm install 0.5s
------
> [5/5] RUN npm install:
0.419 npm error code ENOENT
0.419 npm error syscall open
0.419 npm error path /app/package.json
0.419 npm error errno -2
0.419 npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/app/package.json'
0.419 npm error enoent This is related to npm not being able to find a file.
0.419 npm error enoent
0.420 npm error A complete log of this run can be found in: /root/.npm/_logs/2025-04-04T17_58_38_932Z-debug-0.log
------
Dockerfile:9
--------------------
7 | RUN npm create vite@latest . --template vanilla --yes
8 |
9 | >>> RUN npm install
10 |
11 | EXPOSE 3000
--------------------
ERROR: failed to solve: process "/bin/sh -c npm install" did not complete successfully: exit code: 254
ERROR: Service 'vite' failed to build : Build failed
What is the solution to this issue?