🚀 Docker Production Optimizations: - Chiseled Ubuntu base image for minimal attack surface - Non-root user execution with security hardening - Read-only filesystem with targeted writable volumes - Resource limits (1GB RAM, 1 CPU) with health checks - Multi-stage builds optimized for caching - Zero-downtime deployment automation 🔍 Comprehensive Monitoring Stack: - Prometheus metrics collection with custom rules - Grafana dashboards for application visualization - AlertManager with email notifications for critical events - Fluentd centralized logging with retention policies - Node Exporter + cAdvisor for system/container metrics - Health check endpoint (/health) for container orchestration 📋 Production Deployment Ready: - Complete deployment scripts with backup strategy - Environment templates for secure configuration - Performance monitoring and alerting rules - Enterprise-grade security and observability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
81 lines
2.1 KiB
Docker
81 lines
2.1 KiB
Docker
# Use the official ASP.NET Core runtime image (optimized)
|
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0-jammy-chiseled AS base
|
|
WORKDIR /app
|
|
EXPOSE 8080
|
|
|
|
# Create non-root user for security
|
|
USER $APP_UID
|
|
|
|
# Use the SDK image for building
|
|
FROM mcr.microsoft.com/dotnet/sdk:9.0-jammy AS build
|
|
WORKDIR /src
|
|
|
|
# Copy project files first for better layer caching
|
|
COPY ["LittleShop/LittleShop.csproj", "LittleShop/"]
|
|
COPY ["LittleShop.Client/LittleShop.Client.csproj", "LittleShop.Client/"]
|
|
|
|
# Restore packages in a separate layer
|
|
RUN dotnet restore "LittleShop/LittleShop.csproj" \
|
|
--runtime linux-x64 \
|
|
--no-cache \
|
|
--verbosity minimal
|
|
|
|
# Copy source code
|
|
COPY LittleShop/ LittleShop/
|
|
COPY LittleShop.Client/ LittleShop.Client/
|
|
WORKDIR "/src/LittleShop"
|
|
|
|
# Build with optimizations
|
|
RUN dotnet build "LittleShop.csproj" \
|
|
-c Release \
|
|
-o /app/build \
|
|
--no-restore \
|
|
--verbosity minimal
|
|
|
|
# Publish stage with optimizations
|
|
FROM build AS publish
|
|
RUN dotnet publish "LittleShop.csproj" \
|
|
-c Release \
|
|
-o /app/publish \
|
|
--no-restore \
|
|
--no-build \
|
|
--runtime linux-x64 \
|
|
--self-contained false \
|
|
/p:PublishTrimmed=false \
|
|
/p:PublishSingleFile=false \
|
|
/p:DebugType=None \
|
|
/p:DebugSymbols=false
|
|
|
|
# Final optimized stage
|
|
FROM base AS final
|
|
WORKDIR /app
|
|
|
|
# Switch to root to create directories and set permissions
|
|
USER root
|
|
|
|
# Create directories with proper ownership
|
|
RUN mkdir -p /app/wwwroot/uploads/products \
|
|
&& mkdir -p /app/data \
|
|
&& mkdir -p /app/logs \
|
|
&& chown -R $APP_UID:$APP_UID /app \
|
|
&& chmod -R 755 /app/wwwroot/uploads \
|
|
&& chmod -R 755 /app/data \
|
|
&& chmod -R 755 /app/logs
|
|
|
|
# Copy published app
|
|
COPY --from=publish --chown=$APP_UID:$APP_UID /app/publish .
|
|
|
|
# Switch back to non-root user
|
|
USER $APP_UID
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
|
CMD curl -f http://localhost:8080/health || exit 1
|
|
|
|
# Optimize runtime
|
|
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 \
|
|
DOTNET_RUNNING_IN_CONTAINER=true \
|
|
DOTNET_USE_POLLING_FILE_WATCHER=true \
|
|
ASPNETCORE_FORWARDEDHEADERS_ENABLED=true
|
|
|
|
ENTRYPOINT ["dotnet", "LittleShop.dll"] |