hamza82 commited on
Commit
e616c7b
·
1 Parent(s): 7b738c2

make this code runable and solve error

Browse files
Files changed (2) hide show
  1. Dockerfile +7 -27
  2. nginx.conf +4 -33
Dockerfile CHANGED
@@ -1,43 +1,23 @@
1
  # Stage 1: Build the application
2
  FROM node:16 AS builder
3
-
4
- # Set working directory
5
  WORKDIR /app
6
-
7
- # Copy package.json and package-lock.json (or pnpm-lock.yaml) to work directory
8
  COPY package.json package-lock.json ./
9
-
10
- # Install dependencies
11
  RUN npm install
12
-
13
- # Copy the rest of your app's source code from your host to your image filesystem.
14
  COPY . .
15
-
16
- # Build the application
17
  RUN npm run build
18
 
19
  # Stage 2: Serve the application with Nginx
20
  FROM nginx:alpine
21
-
22
- # Remove default Nginx configuration
23
  RUN rm /etc/nginx/conf.d/default.conf
24
-
25
- # Copy the custom Nginx configuration
26
- COPY nginx.conf /etc/nginx/nginx.conf
27
-
28
- # Set permissions and ownership for Nginx operation directories
29
- RUN mkdir -p /var/cache/nginx && \
30
- chown -R nginx:nginx /var/cache/nginx && \
31
- chmod -R 755 /var/cache/nginx && \
32
- mkdir -p /var/run && \
33
- chown -R nginx:nginx /var/run && \
34
- chmod -R 755 /var/run
35
-
36
  # Copy the built app to Nginx's serve directory
37
  COPY --from=builder /app/dist /usr/share/nginx/html
38
-
 
39
  # Expose port 8080
40
  EXPOSE 8080
41
-
42
- # Start Nginx and keep it running
43
  CMD ["nginx", "-g", "daemon off;"]
 
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
+ # Remove default Nginx configuration files
 
12
  RUN rm /etc/nginx/conf.d/default.conf
13
+ # Create necessary directories with broad permissions
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
+ # Copy custom Nginx configuration
19
+ COPY nginx.conf /etc/nginx/nginx.conf
20
  # Expose port 8080
21
  EXPOSE 8080
22
+ # Override the default command to bypass default entrypoint scripts
 
23
  CMD ["nginx", "-g", "daemon off;"]
nginx.conf CHANGED
@@ -1,45 +1,16 @@
1
- worker_processes auto;
2
 
3
  events {
4
  worker_connections 1024;
5
  }
6
 
7
  http {
8
- include /etc/nginx/mime.types;
9
- default_type application/octet-stream;
10
-
11
- # Logging settings
12
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
13
- '$status $body_bytes_sent "$http_referer" '
14
- '"$http_user_agent" "$http_x_forwarded_for"';
15
- access_log /var/log/nginx/access.log main;
16
- error_log /var/log/nginx/error.log warn;
17
-
18
- # Sendfile settings
19
- sendfile on;
20
- tcp_nopush on;
21
- tcp_nodelay on;
22
- keepalive_timeout 65;
23
- types_hash_max_size 2048;
24
-
25
- # Gzip Settings
26
- gzip on;
27
- gzip_disable "msie6";
28
-
29
  server {
30
- listen 8080;
31
- server_name localhost;
32
 
33
  location / {
34
- root /usr/share/nginx/html;
35
- index index.html index.htm;
36
- try_files $uri $uri/ /index.html;
37
- }
38
-
39
- # Error pages
40
- error_page 500 502 503 504 /50x.html;
41
- location = /50x.html {
42
- root /usr/share/nginx/html;
43
  }
44
  }
45
  }
 
1
+ worker_processes 1;
2
 
3
  events {
4
  worker_connections 1024;
5
  }
6
 
7
  http {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  server {
9
+ listen 8080;
 
10
 
11
  location / {
12
+ root /usr/share/nginx/html;
13
+ index index.html index.htm;
 
 
 
 
 
 
 
14
  }
15
  }
16
  }