-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
49 lines (37 loc) · 1.39 KB
/
Dockerfile
File metadata and controls
49 lines (37 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Multi-stage build for production-ready Docker image
# Stage 1: Build
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /src
# Copy solution and project files
COPY ["src/PulseData.Core/PulseData.Core.csproj", "src/PulseData.Core/"]
COPY ["src/PulseData.Infrastructure/PulseData.Infrastructure.csproj", "src/PulseData.Infrastructure/"]
COPY ["src/PulseData.API/PulseData.API.csproj", "src/PulseData.API/"]
# Restore dependencies
RUN dotnet restore "src/PulseData.API/PulseData.API.csproj"
# Copy entire source
COPY . .
# Build application
WORKDIR "/src/src/PulseData.API"
RUN dotnet build "PulseData.API.csproj" -c Release -o /app/build
# Publish
FROM build AS publish
RUN dotnet publish "PulseData.API.csproj" -c Release -o /app/publish
# Stage 2: Runtime
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
WORKDIR /app
# Install curl for health checks
RUN apk add --no-cache curl
# Copy published application
COPY --from=publish /app/publish .
# Create non-root user for security
RUN addgroup -g 1000 appuser && adduser -D -u 1000 -G appuser appuser && chown -R appuser:appuser /app
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/api/health/live || exit 1
# Expose port
EXPOSE 8000
ENV ASPNETCORE_URLS=http://+:8000
ENV ASPNETCORE_ENVIRONMENT=Production
# Run application
ENTRYPOINT ["dotnet", "PulseData.API.dll"]