This repository was archived by the owner on Mar 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (36 loc) · 1.47 KB
/
Dockerfile
File metadata and controls
47 lines (36 loc) · 1.47 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
# Use the official .NET 9.0 SDK image for building
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
# Copy project file and restore dependencies (better layer caching)
COPY ["modelcontextprotocol.csproj", "./"]
RUN dotnet restore "modelcontextprotocol.csproj" --runtime linux-x64
# Copy source code and build the application
COPY . .
RUN dotnet publish "modelcontextprotocol.csproj" -c Release -o /app/publish \
--no-restore \
--self-contained true \
--runtime linux-x64 \
/p:PublishTrimmed=false
# Use a minimal base image for self-contained deployment
FROM mcr.microsoft.com/dotnet/runtime-deps:9.0 AS runtime
# Install curl for health checks
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Create a non-root user for security
RUN adduser --disabled-password --gecos '' --uid 1001 appuser && \
chown -R appuser:appuser /app
USER appuser
# Copy the published application from the build stage
COPY --from=build /app/publish .
# Expose the port the app runs on
EXPOSE 8080
# Set environment variables for ASP.NET Core
ENV ASPNETCORE_URLS=http://0.0.0.0:8080 \
ASPNETCORE_ENVIRONMENT=Production \
DOTNET_RUNNING_IN_CONTAINER=true \
DOTNET_USE_POLLING_FILE_WATCHER=true
# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Run the self-contained application
ENTRYPOINT ["./SandboxModelContextProtocol.Server"]