make this code runable and solve error
Browse files- Dockerfile +17 -7
- nginx.conf +21 -4
Dockerfile
CHANGED
@@ -1,23 +1,33 @@
|
|
1 |
# Stage 1: Build the application
|
2 |
FROM node:16 AS builder
|
|
|
3 |
WORKDIR /app
|
|
|
4 |
COPY package.json package-lock.json ./
|
|
|
5 |
RUN npm install
|
|
|
6 |
COPY . .
|
|
|
7 |
RUN npm run build
|
8 |
|
9 |
# Stage 2: Serve the application with Nginx
|
10 |
FROM nginx:alpine
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
RUN mkdir -p /var/cache/nginx/client_temp /var/cache/nginx/proxy_temp /var/cache/nginx/fastcgi_temp /var/cache/nginx/uwsgi_temp /var/cache/nginx/scgi_temp && \
|
15 |
-
chmod -R 777 /var/cache/nginx
|
16 |
# Copy the built app to Nginx's serve directory
|
17 |
COPY --from=builder /app/dist /usr/share/nginx/html
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
19 |
COPY nginx.conf /etc/nginx/nginx.conf
|
|
|
20 |
# Expose port 8080
|
21 |
EXPOSE 8080
|
22 |
-
|
|
|
23 |
CMD ["nginx", "-g", "daemon off;"]
|
|
|
1 |
# Stage 1: Build the application
|
2 |
FROM node:16 AS builder
|
3 |
+
|
4 |
WORKDIR /app
|
5 |
+
|
6 |
COPY package.json package-lock.json ./
|
7 |
+
|
8 |
RUN npm install
|
9 |
+
|
10 |
COPY . .
|
11 |
+
|
12 |
RUN npm run build
|
13 |
|
14 |
# Stage 2: Serve the application with Nginx
|
15 |
FROM nginx:alpine
|
16 |
+
|
17 |
+
# Start as root to perform initial setup tasks
|
18 |
+
|
|
|
|
|
19 |
# Copy the built app to Nginx's serve directory
|
20 |
COPY --from=builder /app/dist /usr/share/nginx/html
|
21 |
+
|
22 |
+
# Create directories and set permissions
|
23 |
+
RUN mkdir -p /var/cache/nginx /var/run /var/log/nginx /var/tmp/nginx && \
|
24 |
+
chmod -R 777 /var/cache/nginx /var/run /var/log/nginx /var/tmp/nginx
|
25 |
+
|
26 |
+
# Provide a custom nginx.conf that sets pid and client_body_temp_path to directories with proper permissions
|
27 |
COPY nginx.conf /etc/nginx/nginx.conf
|
28 |
+
|
29 |
# Expose port 8080
|
30 |
EXPOSE 8080
|
31 |
+
|
32 |
+
# Start Nginx in the foreground
|
33 |
CMD ["nginx", "-g", "daemon off;"]
|
nginx.conf
CHANGED
@@ -1,16 +1,33 @@
|
|
1 |
-
|
|
|
|
|
|
|
2 |
|
3 |
events {
|
4 |
worker_connections 1024;
|
5 |
}
|
6 |
|
7 |
http {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
server {
|
9 |
-
listen
|
|
|
10 |
|
11 |
location / {
|
12 |
-
root
|
13 |
-
index
|
14 |
}
|
15 |
}
|
16 |
}
|
|
|
1 |
+
user nginx;
|
2 |
+
worker_processes auto;
|
3 |
+
pid /var/run/nginx.pid;
|
4 |
+
error_log /var/log/nginx/error.log warn;
|
5 |
|
6 |
events {
|
7 |
worker_connections 1024;
|
8 |
}
|
9 |
|
10 |
http {
|
11 |
+
include /etc/nginx/mime.types;
|
12 |
+
default_type application/octet-stream;
|
13 |
+
client_body_temp_path /var/tmp/nginx/client_body;
|
14 |
+
|
15 |
+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
16 |
+
'$status $body_bytes_sent "$http_referer" '
|
17 |
+
'"$http_user_agent" "$http_x_forwarded_for"';
|
18 |
+
|
19 |
+
access_log /var/log/nginx/access.log main;
|
20 |
+
|
21 |
+
sendfile on;
|
22 |
+
keepalive_timeout 65;
|
23 |
+
|
24 |
server {
|
25 |
+
listen 8080;
|
26 |
+
server_name localhost;
|
27 |
|
28 |
location / {
|
29 |
+
root /usr/share/nginx/html;
|
30 |
+
index index.html index.htm;
|
31 |
}
|
32 |
}
|
33 |
}
|