-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
61 lines (46 loc) · 1.45 KB
/
Copy pathdockerfile
File metadata and controls
61 lines (46 loc) · 1.45 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
55
56
57
58
59
60
61
# ===========================
# Stage 1: Build
# ===========================
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
# Set NuGet location for caching
ENV NUGET_PACKAGES=/src/nugetpackages
# Copy solution + dependency files (cache restore layer)
COPY *.sln .
COPY Directory.Packages.props .
COPY src/Api/Api.csproj src/Api/
COPY src/Core/Core.csproj src/Core/
COPY src/Library/Library.csproj src/Library/
# Restore dependencies (cached)
RUN dotnet restore
# Copy full source
COPY . .
# Build & publish
WORKDIR /src/src/Api
RUN dotnet publish -c Release -o /app/publish --no-restore
# ===========================
# Stage 2: Runtime
# ===========================
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
WORKDIR /app
# Create non-root runtime user (recommended)
RUN addgroup --system appgroup \
&& adduser --system --ingroup appgroup appuser
# Copy runtime build
COPY --from=build /app/publish .
# Create persistent app data dir
RUN mkdir -p /app/data \
&& chown -R appuser:appgroup /app/data \
&& chmod -R 755 /app/data
# Env variables (must match your docker-compose)
ENV ASPNETCORE_ENVIRONMENT=Production \
ASPNETCORE_URLS=http://+:5000
# Expose API port
EXPOSE 5000
# Switch to non-root user
USER appuser
# Start application
ENTRYPOINT ["dotnet", "Api.dll"]
LABEL maintainer="nasim@gmail.com" \
description="Rental API (Optimized)" \
version="1.0"