Spaces:
Running
Running
# Build stage | |
FROM node:20-alpine as build | |
WORKDIR /app | |
# Copy package.json and install dependencies | |
COPY package*.json ./ | |
RUN npm ci | |
# Copy the rest of the application code | |
COPY . . | |
# Build the app | |
RUN npm run build | |
# Production stage with nginx | |
FROM nginx:alpine | |
# Copy built app to nginx | |
COPY --from=build /app/build /usr/share/nginx/html | |
COPY nginx.conf /etc/nginx/conf.d/default.conf | |
# Create a proper nginx.conf using /dev/shm which is usually writable in containers | |
RUN { \ | |
echo 'worker_processes auto;'; \ | |
echo 'error_log /dev/stderr warn;'; \ | |
echo 'pid /dev/shm/nginx.pid;'; \ | |
echo 'events {'; \ | |
echo ' worker_connections 1024;'; \ | |
echo '}'; \ | |
echo 'http {'; \ | |
echo ' include /etc/nginx/mime.types;'; \ | |
echo ' default_type application/octet-stream;'; \ | |
echo ' client_body_temp_path /dev/shm/client_temp;'; \ | |
echo ' proxy_temp_path /dev/shm/proxy_temp;'; \ | |
echo ' fastcgi_temp_path /dev/shm/fastcgi_temp;'; \ | |
echo ' uwsgi_temp_path /dev/shm/uwsgi_temp;'; \ | |
echo ' scgi_temp_path /dev/shm/scgi_temp;'; \ | |
echo ' log_format main "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\"";'; \ | |
echo ' access_log /dev/stdout main;'; \ | |
echo ' sendfile on;'; \ | |
echo ' keepalive_timeout 65;'; \ | |
echo ' include /etc/nginx/conf.d/*.conf;'; \ | |
echo '}'; \ | |
} > /etc/nginx/nginx.conf | |
# Create necessary directories in /dev/shm for nginx temp files | |
RUN mkdir -p /dev/shm/client_temp \ | |
/dev/shm/proxy_temp \ | |
/dev/shm/fastcgi_temp \ | |
/dev/shm/uwsgi_temp \ | |
/dev/shm/scgi_temp | |
# Expose port | |
EXPOSE 3000 | |
# Start nginx | |
CMD ["nginx", "-g", "daemon off;"] |