-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
46 lines (34 loc) · 1.71 KB
/
Copy pathDockerfile
File metadata and controls
46 lines (34 loc) · 1.71 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
# =====================
# Build stage
# =====================
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /src
# 1. Copy các file csproj để restore trước (Tận dụng Docker Layer Caching)
COPY PokedexReactASP.Domain/PokedexReactASP.Domain.csproj PokedexReactASP.Domain/
COPY PokedexReactASP.Application/PokedexReactASP.Application.csproj PokedexReactASP.Application/
COPY PokedexReactASP.Infrastructure/PokedexReactASP.Infrastructure.csproj PokedexReactASP.Infrastructure/
COPY PokedexReactASP.Server/PokedexReactASP.Server.csproj PokedexReactASP.Server/
# Giúp Self-hosted Runner không phải tải lại các gói từ internet nếu có sự thay đổi nhỏ ở mã nguồn.
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
dotnet restore "PokedexReactASP.Server/PokedexReactASP.Server.csproj" /p:Configuration=Release
# 2. Copy toàn bộ source code còn lại và tiến hành publish
COPY . .
WORKDIR /src/PokedexReactASP.Server
RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \
dotnet publish -c Release -o /app/publish
# =====================
# Runtime stage
# =====================
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
# Cài đặt thư viện ICU để hỗ trợ Globalization (Tiếng Việt, sắp xếp dữ liệu, múi giờ)
RUN apk add --no-cache icu-libs
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \
DOTNET_GC_SERVER=1 \
DOTNET_RUNNING_IN_CONTAINER=true
WORKDIR /app
COPY --from=build --chown=app:app /app/publish .
USER app
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
CMD wget -qO- http://localhost:8080/health > /dev/null || exit 1
ENTRYPOINT ["dotnet", "PokedexReactASP.Server.dll"]