I would like to dockerize and create a build process for a simple Vue.js application using Dockerfile. But, I get some errors when building from NGINX, it looks like the static build files of the project are missing. When I log in to localhost:8080
- I get an empty page, and in the console the following messages:
2023/01/06 07:00:03 [error] 30#30: *1 open() "/usr/share/nginx/html/vue-ims/js/chunk-vendors.97986597.js" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /vue-ims/js/chunk-vendors.97986597.js HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/"
...
I tried to access the /usr/share/nginx folder inside the container, but nothing was visible there. During the dockerfile build process, it should COPY
all the necessary files to certain folders that should be accessible, but seems like nothing happened.
Dockerfile:
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json .env ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
I also tried to build without the production stage as mentioned in comments, checked the /app/dist, /js/ folder inside the container and got the files there.
CodePudding user response:
Thanks to @bassxzero solved this problem.
nginx.conf:
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
}