Dockerfileβ’1.55 kB
# Multi-stage build for production optimization
FROM node:18-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY tsconfig.json ./
# Install ALL dependencies (including devDependencies for build)
RUN npm ci && npm cache clean --force
# Copy source code
COPY src/ ./src/
# Build the application
RUN npm run build
# Production stage
FROM node:18-alpine AS production
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Create app directory and user
RUN addgroup -g 1001 -S nodejs && \
adduser -S appuser -u 1001 -G nodejs
WORKDIR /app
# Copy package files and install production dependencies
COPY package*.json ./
RUN npm ci --only=production && npm cache clean --force
# Copy built application from builder stage
COPY --from=builder /app/dist ./dist
# Create logs directory
RUN mkdir -p logs && chown -R appuser:nodejs logs
# Copy configuration files
COPY .env.example ./.env.example
# Set ownership of app directory
RUN chown -R appuser:nodejs /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 3000
# Health check - Disabled temporarily for EasyPanel compatibility
# HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
# CMD node -e "require('http').get('http://localhost:3000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Start the application
CMD ["node", "dist/index.js"]