Add Docker support: multi-stage Dockerfile
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
# ---- Build ----
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
COPY NoticeBoard.csproj ./
|
||||
RUN dotnet restore NoticeBoard.csproj
|
||||
|
||||
COPY . .
|
||||
RUN dotnet publish NoticeBoard.csproj -c Release -o /app/publish --no-restore
|
||||
|
||||
# ---- Runtime ----
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=build /app/publish .
|
||||
|
||||
# Make sure the folders that need to be writable exist even before a volume is mounted
|
||||
RUN mkdir -p /data /app/wwwroot/uploads
|
||||
|
||||
ENV ASPNETCORE_HTTP_PORTS=8080 \
|
||||
ASPNETCORE_ENVIRONMENT=Production \
|
||||
DataDirectory=/data
|
||||
|
||||
EXPOSE 8080
|
||||
VOLUME ["/data", "/app/wwwroot/uploads"]
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
|
||||
CMD bash -c 'exec 3<>/dev/tcp/127.0.0.1/8080 && exec 3<&-' || exit 1
|
||||
|
||||
ENTRYPOINT ["dotnet", "NoticeBoard.dll"]
|
||||
Reference in New Issue
Block a user