- Use 'npx serve' for static file serving - Avoid Astro preview host restrictions - Serve all routes from dist/ folder - Fixes 403 forbidden errors - Better for static Astro sites with API endpoints
42 lines
822 B
Docker
42 lines
822 B
Docker
# Build Stage
|
|
FROM node:20-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
COPY package*.json ./
|
|
RUN npm install
|
|
|
|
COPY . .
|
|
RUN mkdir -p data
|
|
|
|
# Build project
|
|
RUN npm run build
|
|
|
|
# Production Stage
|
|
FROM node:20-alpine
|
|
|
|
WORKDIR /app
|
|
|
|
# Install SQLite runtime
|
|
RUN apk add --no-cache sqlite-libs
|
|
|
|
COPY package*.json ./
|
|
RUN npm install --production
|
|
|
|
# Copy built assets
|
|
COPY --from=builder /app/dist ./dist
|
|
COPY --from=builder /app/data ./data
|
|
|
|
EXPOSE 80
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD node -e "require('http').get('http://localhost:80', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
|
|
|
ENV NODE_ENV=production
|
|
ENV ASTRO_PORT=80
|
|
ENV ASTRO_HOST=0.0.0.0
|
|
|
|
# Serve static files using serve package with all-host access
|
|
CMD ["npx", "serve", "--listen", "80", "--single", "dist"]
|