Skip to content

Commit

Permalink
chore: replace base image with -alpine (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
vehecap authored Feb 4, 2025
1 parent 6ef74b2 commit 71f567b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
# Use the .NET 8 SDK image based on Alpine
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /app

# Install additional packages
RUN apk add --no-cache libc6-compat icu

# Copy csproj and restore as distinct layers
# TODO: Copy only csproj
COPY . .
COPY ./Oplog.Api/Oplog.Api.csproj ./Oplog.Api/Oplog.Api.csproj
COPY ./Oplog.Core/Oplog.Core.csproj ./Oplog.Core/Oplog.Core.csproj
COPY ./Oplog.Persistence/Oplog.Persistence.csproj ./Oplog.Persistence/Oplog.Persistence.csproj

RUN dotnet restore Oplog.Api/Oplog.Api.csproj

# Copy everything else and build
# TODO: Copy rest of files
# COPY . ./
COPY . ./
RUN dotnet publish Oplog.Api -c Release -o Oplog.Api/out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
# Build runtime image based on Alpine
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
WORKDIR /app
COPY --from=build-env /app/Oplog.Api/out .

RUN addgroup --gid 1001 radix-non-root-group
RUN adduser --uid 1001 --gid 1001 radix-non-root-user
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
ENV TZ="Europe/Oslo"
RUN apk -U add --no-cache icu tzdata

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

USER 1001
# Create a non-root user and group with numeric UID/GID
RUN addgroup -g 1001 non-root-group && \
adduser -u 1001 -G non-root-group -s /bin/sh -D non-root-user

# Switch to the non-root user
USER 1001:1001

EXPOSE 5000

ENTRYPOINT ["dotnet", "Oplog.Api.dll"]

0 comments on commit 71f567b

Please sign in to comment.