Clean up the docker file

pull/1032/head
Tyrrrz 2 years ago
parent b9cd40f211
commit c3f181c9e0

@ -1,5 +1,7 @@
# -- Build # -- Build
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build # Use the same platform for the build image as the runtime image, so that it's easier
# to produce a self-contained assembly for the right platform.
FROM mcr.microsoft.com/dotnet/sdk:7.0-runtime AS build
WORKDIR /build WORKDIR /build
@ -9,6 +11,7 @@ COPY Directory.Build.props ./
COPY DiscordChatExporter.Core ./DiscordChatExporter.Core COPY DiscordChatExporter.Core ./DiscordChatExporter.Core
COPY DiscordChatExporter.Cli ./DiscordChatExporter.Cli COPY DiscordChatExporter.Cli ./DiscordChatExporter.Cli
# Publish a self-contained assembly so we can use a slimmer runtime image
RUN dotnet publish DiscordChatExporter.Cli \ RUN dotnet publish DiscordChatExporter.Cli \
--self-contained \ --self-contained \
--use-current-runtime \ --use-current-runtime \
@ -16,29 +19,27 @@ RUN dotnet publish DiscordChatExporter.Cli \
--output ./publish --output ./publish
# -- Run # -- Run
# Use Alpine for the runtime image due to its smaller size.
# Use `runtime-deps` instead of `runtime` since we're running a self-contained assembly.
# https://github.com/dotnet/dotnet-docker/blob/main/samples/selecting-tags.md
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine
# Alpine dotnet image doesn't include timezone data, which is needed # Alpine image doesn't include timezone data, which is needed for certain date/time operations
# for certain date/time operations. # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
RUN apk add --no-cache tzdata RUN apk add --no-cache tzdata
# Create a non-root user to run the app, so that the output files # Create a non-root user to run the app, so that the output files can be accessed by the host
# can be accessed by the host.
# https://github.com/Tyrrrz/DiscordChatExporter/issues/851 # https://github.com/Tyrrrz/DiscordChatExporter/issues/851
RUN adduser \ RUN adduser --disabled-password --no-create-home dce
--disabled-password \
--no-create-home \
dce
USER dce USER dce
COPY --from=build /build/publish /opt/dce COPY --from=build /build/publish /opt/dce
# Need to keep this as /out for backwards compatibility with documentation. # Add the app directory to the PATH so that it's easier to run the app via `docker exec`
# A lot of people have this directory mounted in their scripts files, so ENV PATH="$PATH:/opt/dce"
# changing it would break existing workflows.
# This directory is exposed to the user for mounting purposes, so it's important
# that it stays the same for backwards compatibility.
WORKDIR /out WORKDIR /out
# Add the app directory to PATH so that it's easier to debug using a shell
ENV PATH="$PATH:/opt/dce"
ENTRYPOINT ["DiscordChatExporter.Cli"] ENTRYPOINT ["DiscordChatExporter.Cli"]

Loading…
Cancel
Save