{"id":15683454,"url":"https://github.com/kant2002/nativeaotdocker","last_synced_at":"2025-05-07T13:03:30.972Z","repository":{"id":62298073,"uuid":"382797983","full_name":"kant2002/NativeAOTDocker","owner":"kant2002","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-16T07:38:14.000Z","size":166,"stargazers_count":24,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T13:03:22.389Z","etag":null,"topics":["docker","nativeaot"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kant2002.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-04T08:10:07.000Z","updated_at":"2024-12-23T07:57:25.000Z","dependencies_parsed_at":"2023-02-12T21:30:34.882Z","dependency_job_id":null,"html_url":"https://github.com/kant2002/NativeAOTDocker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kant2002%2FNativeAOTDocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kant2002%2FNativeAOTDocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kant2002%2FNativeAOTDocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kant2002%2FNativeAOTDocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kant2002","download_url":"https://codeload.github.com/kant2002/NativeAOTDocker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252883227,"owners_count":21819158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","nativeaot"],"created_at":"2024-10-03T17:05:38.346Z","updated_at":"2025-05-07T13:03:30.915Z","avatar_url":"https://github.com/kant2002.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"Scratch docker image using C#\n=============================\n\nThis repository is sample how to statically link console application into single executable and run on Docker.\n\n# Results\n\nThis is sizes for experiment\n\n| Experiment | Size | Embed ICU | Embed OpenSSL | \n| ------------ | ----- | --- | ---------- |\n| Console + Invariant globalization | 1.29 MB | No | No |\n| Console + ICU | 35.14 MB | Yes | No |\n| Console + Brotli + Deflate + Gzip | 2.22 MB  | No | No |\n| HttpClient | 7.26 MB | No | No |\n| HttpClient + OpenSSL | 12.16 MB | No | Yes |\n| Web API | 21.94 MB | No | Yes |\n| Grpc API | 23.46 MB | No | Yes |\n| Npgsql ADO.NET + ICU | 50.98 MB | Yes | Yes |\n| Npgsql ADO.NET + Invariant globalization | 17.08 MB | No | Yes |\n| Npgsql Builder Slim + ICU | 44.1 MB | Yes | Yes |\n| Npgsql Builder Slim + Invariant globalization | 10.2 MB | No | Yes |\n\nChilsed for comparison\n\n| Experiment | Size | Embed ICU | Embed OpenSSL | \n| ------------ | ----- | --- | ---------- |\n| Web API | 30.46 MB | No | No |\n\nResulting docker image have size of 1.56 MB. Thats after disabling reflection. That's the minimum which I can get without integrating with Docker tightly. Or is it kernel integration I'm dreaming about? Unikernels, I see unikernels around me\n\n# Sizes of the components\n\nBased on results I get approximate minimum size of code which added to your application if you using these libraries.\n\n| Component | Size |\n| ------------ | ----- |\n| Barebone runtime + console | 1.28MB |\n| ICU data | 29.40MB |\n| Globalization support | 4.47MB |\n| Brotli + Deflate + Gzip | 0.94MB |\n| HttpClient | 5.98MB |\n| OpenSSL | 4.26MB |\n| OpenSSL certificates | 0.64MB |\n| Web API | 20.66MB |\n| Grpc API | 22.18MB |\n| Npgsql ADO.NET | 15.82MB |\n| Npgsql Builder Slim | 8.93MB |\n\n# Build and Run\n\n## Embedded ICU - 35.14 MB\n```shell\ndocker build -t nativeaot-scratch EmbeddedICU \ndocker run -i nativeaot-scratch\n```\n\n30 MB is ICU data.\n\n## Invariant globalization - 1.29 MB\n```shell\ndocker build -t nativeaot-scratch-invariant InvariantGlobalization\ndocker run -i nativeaot-scratch-invariant\n```\n\n## Brotli + Deflate + Gzip - 2.22 MB\n```shell\ndocker build -t nativeaot-scratch-compression CompressionEmbedding\ndocker run -i nativeaot-scratch-compression\n```\n\n## HttpClient - 7.26 MB\nwith reflection unfortunately\n```shell\ndocker build -t nativeaot-scratch-http-client -f OpenSslEmbedding/Dockerfile.nossl OpenSslEmbedding\ndocker run -i nativeaot-scratch-http-client\n```\n\n## HttpClient + OpenSSL - 12.16 MB\nwith reflection unfortunately\n```shell\ndocker build -t nativeaot-scratch-openssl OpenSslEmbedding\ndocker run -i nativeaot-scratch-openssl\n```\n\n## Web API - 21.94 MB\nwith reflection unfortunately\n```shell\ndocker build -t nativeaot-scratch-webapi WebApi\ndocker run -p 5022:80 -i nativeaot-scratch-webapi\n```\n\nWeb API accessible on http://localhost:5022.\n\nFor SSL configuration take a look at https://learn.microsoft.com/en-us/dotnet/core/additional-tools/self-signed-certificates-guide#with-openssl nd create `certs` folder with certificates. Then you can run following command.\n\n```\ndocker run --rm -it -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS=\"https://+;http://+\" -e ASPNETCORE_HTTPS_PORT=8001 -e ASPNETCORE_ENVIRONMENT=Development -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/contoso.com.crt -e ASPNETCORE_Kestrel__Certificates__Default__KeyPath=/https/contoso.com.key -v $PWD\\certs/:/https/ nativeaot-scratch-webapi\n```\n\nWeb API accessible on http://localhost:8000 and https://localhost:8001.\n\n## GrpcApi - 23.46 MB\nwith reflection unfortunately\n```shell\ndocker build -t nativeaot-scratch-grpcapi GrpcApi\ndocker run --rm -it -p 8010:80 -p 8011:443 -e ASPNETCORE_URLS=\"https://+;http://+\" -e ASPNETCORE_HTTPS_PORT=8001 -e ASPNETCORE_ENVIRONMENT=Development -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/contoso.com.crt -e ASPNETCORE_Kestrel__Certificates__Default__KeyPath=/https/contoso.com.key -v $PWD\\certs/:/https/ nativeaot-scratch-grpcapi\n``` \n\n## NpgCli + Globalization - 50.98 MB\nwith reflection unfortunately\n```shell\ndocker build -t nativeaot-scratch-npgsql NpgCli\ndocker run -i -e ConnectionString='Host=172.17.0.2;Username=postgres;Password=postgrespw' nativeaot-scratch-npgsql\n```\n\n## NpgCli - 17.08 MB\nwith reflection unfortunately\n```shell\ndocker build -t nativeaot-scratch-npgsql-noicu NpgCli -f NpgCli/Dockerfile.noicu\ndocker run -i -e ConnectionString='Host=172.17.0.2;Username=postgres;Password=postgrespw' nativeaot-scratch-npgsql-noicu\n```\n\n## Web API on Chiseled - 30.46 MB\nwith reflection unfortunately\n```shell\ndocker build -t nativeaot-scratch-webapi-chiseled WebApiChiseled\ndocker run -p 5122:80 -i nativeaot-scratch-webapi-chiseled\n```\n\nWeb API accessible on http://localhost:5122.\n\ndocker run --rm -it -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS=\"https://+;http://+\" -e ASPNETCORE_HTTPS_PORT=8001 -e ASPNETCORE_ENVIRONMENT=Development -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/contoso.com.crt -e ASPNETCORE_Kestrel__Certificates__Default__KeyPath=/https/contoso.com.key -v $PWD\\certs/:/https/ nativeaot-scratch-webapi\n\n\n# Inspeciting scratch container\n\nYou can use dive\n```shell\ndocker run --rm -it `\n     -v /var/run/docker.sock:/var/run/docker.sock `\n     wagoodman/dive:latest nativeaot-scratch\n```\n\nor export tar with container\n\n```\ndocker save nativeaot-scratch -o nativeaot-scratch.tar\n```\n\n# Testing that building inside Alpine works.\n\nThat's was needed when NativeAOT does not have objwriter for musl. Still interesting if you need to build augment ObjWriter.\n```\ndocker build -t test-build -f Dockerfile.objwriter .\n```\n\n# Smoke test for ObjWriter build\n\n```\ndocker build -t nativeaot-scratch-build -f Dockerfile.objwriter .\ndocker run -i nativeaot-scratch-build\n```\n\nCompiled `libobjwriter.so` is located at `artifacts/obj/InstallRoot-/lib` inside docker.\n\n\n```\ndocker run --name postgres-aot -e \"POSTGRES_USER=postgres\" -e \"POSTGRES_PASSWORD=postgrespw\" -p 5432:32768 -d postgres\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkant2002%2Fnativeaotdocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkant2002%2Fnativeaotdocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkant2002%2Fnativeaotdocker/lists"}