-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (39 loc) · 1.54 KB
/
Dockerfile
File metadata and controls
54 lines (39 loc) · 1.54 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
50
51
52
53
54
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:9.0-bookworm-slim AS build
WORKDIR /src
# Copy solution and project files
COPY ["AbeckDev.DbTimetable.sln", "./"]
COPY ["AbeckDev.DbTimetable.Mcp/AbeckDev.DbTimetable.Mcp.csproj", "AbeckDev.DbTimetable.Mcp/"]
COPY ["AbeckDev.DbTimetable.Mcp.Test/AbeckDev.DbTimetable.Mcp.Test.csproj", "AbeckDev.DbTimetable.Mcp.Test/"]
# Restore dependencies
RUN dotnet restore "AbeckDev.DbTimetable.Mcp/AbeckDev.DbTimetable.Mcp.csproj"
# Copy the rest of the source code
COPY . .
# Build the application
WORKDIR "/src/AbeckDev.DbTimetable.Mcp"
RUN dotnet build "AbeckDev.DbTimetable.Mcp.csproj" -c Release -o /app/build
# Publish stage
FROM build AS publish
RUN dotnet publish "AbeckDev.DbTimetable.Mcp.csproj" -c Release -o /app/publish /p:UseAppHost=false
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:9.0-bookworm-slim AS final
WORKDIR /app
# Install curl for healthcheck
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
# Create a non-root user
RUN groupadd -r appuser && useradd -r -g appuser appuser
# Copy published files
COPY --from=publish /app/publish .
# Change ownership to non-root user
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 3001
# Set environment variables
ENV ASPNETCORE_URLS=http://0.0.0.0:3001
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3001/ || exit 1
# Entry point
ENTRYPOINT ["dotnet", "AbeckDev.DbTimetable.Mcp.dll"]