40 lines
857 B
Docker
40 lines
857 B
Docker
# Dockerfile for Astro webapp with NGINX for production
|
|
# Stage 1: Build the Astro application
|
|
FROM node:20-alpine as build
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy package files and install dependencies
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci
|
|
|
|
# Copy the rest of the application code
|
|
COPY . .
|
|
|
|
# Build the Astro project
|
|
RUN npm run build
|
|
|
|
# Stage 2: Serve with NGINX
|
|
FROM nginx:alpine
|
|
|
|
# Copy built static files from build stage to NGINX html directory
|
|
COPY --from=build /app/dist /usr/share/nginx/html
|
|
|
|
# Add custom NGINX configuration if needed
|
|
RUN echo 'server {\
|
|
listen 80;\
|
|
server_name _;\
|
|
root /usr/share/nginx/html;\
|
|
index index.html;\
|
|
location / {\
|
|
try_files $uri $uri/ /index.html;\
|
|
}\
|
|
}' > /etc/nginx/conf.d/default.conf
|
|
|
|
# Expose port 80
|
|
EXPOSE 80
|
|
|
|
# Start NGINX
|
|
CMD ["nginx", "-g", "daemon off;"]
|