Skip to main content

Dockerfile for building a .NET Core API.

# Use the official .NET Core SDK image based on Alpine for building the project
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build

# Install necessary packages for globalization and time zone support
RUN apk add --no-cache icu-libs tzdata

# Set the environment variable to use the ICU libraries for globalization
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

# Set the working directory inside the container
WORKDIR /app

# Copy the project files to the working directory
COPY . ./

# Restore the project dependencies
RUN dotnet restore

# Build the project
RUN dotnet build -c Release -o /out

# Publish the project
RUN dotnet publish -c Release -o /out

# Use the official .NET Core runtime image based on Alpine for running the application
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine

# Install necessary packages for globalization and time zone support
RUN apk add --no-cache icu-libs tzdata

# Set the environment variable to use the ICU libraries for globalization
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

# Set the time zone (example: UTC)
ENV TZ=UTC

# Copy the published output from the build stage
COPY --from=build /out /app

# Set the working directory inside the container
WORKDIR /app

# Expose the port the application runs on
EXPOSE 80

# Set the entry point for the application
ENTRYPOINT ["dotnet", "YourProjectName.dll"]