Skip to content

Switch runtime base image to aspnet:10.0-alpine to reduce image size #456

@nanotaboada

Description

@nanotaboada

Problem

The current runtime base image is mcr.microsoft.com/dotnet/aspnet:10.0, which is Debian-based. The Alpine equivalent offers a meaningfully smaller footprint with no functional difference for this application.

Estimated size reduction: ~100–150 MB.

Proposed Solution

Switch the runtime stage FROM to the Alpine variant:

# Replace:
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime

# With:
FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS runtime

This is the quickest size win available for this repo and requires only Dockerfile changes.

Suggested Approach

1. Update the runtime FROM

FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS runtime

2. Replace apt-get with apk

Alpine uses apk, not apt-get:

# Replace:
RUN apt-get update && apt-get install -y --no-install-recommends curl && \
    rm -rf /var/lib/apt/lists/*

# With:
RUN apk add --no-cache curl

3. Replace groupadd/useradd with Alpine equivalents

# Replace:
RUN groupadd -r aspnetcore && useradd -r -g aspnetcore aspnetcore && \
    mkdir -p /storage && \
    chown aspnetcore:aspnetcore /storage

# With:
RUN addgroup -S aspnetcore && \
    adduser -S -G aspnetcore aspnetcore && \
    mkdir -p /storage && \
    chown aspnetcore:aspnetcore /storage

4. Validate ICU / globalization

Alpine .NET images default to InvariantGlobalization=true. Verify whether the application relies on culture-sensitive operations (date formatting, string comparison with locale). If it does, add:

ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
RUN apk add --no-cache icu-libs

If the application is culture-invariant (likely for a REST API with ISO-8601 dates and ASCII-only player data), no change is needed.

5. Key files to modify

  • Dockerfile — runtime FROM, apt-getapk, groupadd/useraddaddgroup/adduser

No application code changes are required.

Relationship to other issues

This issue addresses image size. The DHI migration issue (security hardening) is separate and can be applied on top of whichever base this issue lands on — DHI also offers an Alpine-based .NET runtime variant.

Acceptance Criteria

  • Runtime stage uses mcr.microsoft.com/dotnet/aspnet:10.0-alpine
  • apt-get replaced with apk throughout the runtime stage
  • groupadd/useradd replaced with addgroup/adduser
  • Application builds and starts correctly
  • All existing endpoints respond correctly
  • Health check passes
  • All CI tests pass
  • Image size is measurably smaller than the Debian baseline (document before/after)
  • Globalization behavior validated (invariant mode or ICU explicitly configured)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    containersPull requests that update containers codedotnetPull requests that update .NET codeenhancementNew feature or requestpriority:mediumPlanned enhancement. Queue for upcoming work.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions