Skip to content

Instantly share code, notes, and snippets.

@Guiorgy
Last active December 6, 2025 12:27
Show Gist options
  • Select an option

  • Save Guiorgy/7c983ec949b7982470db82582dc654ea to your computer and use it in GitHub Desktop.

Select an option

Save Guiorgy/7c983ec949b7982470db82582dc654ea to your computer and use it in GitHub Desktop.
Publish a .NET AOT project for Linux on a Windows host using Docker
# Copyright © 2025 Guiorgy
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
# You can see the full GNU General Public License at
# <https://www.gnu.org/licenses/> for more details.
services:
builder:
container_name: DotNet_Builder
user: "${UID:-1000}"
build:
context: .
dockerfile: Dockerfile.builder
args:
UID: "${UID:-1000}"
working_dir: /build
volumes:
- .:/build:rw
command: >
/bin/sh -c '
dotnet publish MyApp.csproj /p:PublishProfile=Properties/PublishProfiles/Release.pubxml;
'
# Usage: docker compose run --rm builder
# Copyright © 2025 Guiorgy
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
# You can see the full GNU General Public License at
# <https://www.gnu.org/licenses/> for more details.
FROM mcr.microsoft.com/dotnet/sdk:10.0-aot
RUN apt-get -qq update \
&& apt-get -qq upgrade \
# Install dependencies, e.g. time zone data
#&& apt-get -qq install \
# tzdata \
&& rm -rf /var/lib/apt/lists/* \
&& dotnet workload update
ARG UID=1000
RUN userdel ubuntu \
&& useradd --non-unique --uid ${UID} --user-group --no-create-home --home /build --shell /sbin/nologin --comment Builder builder \
&& mkdir /build \
&& chown builder:builder /build
USER builder:builder
WORKDIR /build
@Guiorgy
Copy link
Author

Guiorgy commented Sep 17, 2024

Notes

Modify MyApp.csproj accordingly.

If you need to use a different SDK from .NET 10.0, then change the base image tag from mcr.microsoft.com/dotnet/sdk:10.0-aot. You can find the full list of available .NET SDK tags here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment