├── .gitignore ├── 1-nginx ├── Dockerfile └── wwwroot │ └── index.html ├── 10-bullseyeslim-net6 ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 11-runtimedeps-net6 ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 12-distroless2-net6 ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj ├── tmp.tar └── wwwroot │ └── index.html ├── 12a-distroless2-net6-aggressivetrim ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj ├── tmp.tar └── wwwroot │ └── index.html ├── 13-bullseyeslim-net7 ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 14-distroless-net7-aggressivetrim ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json ├── appsettings.json ├── global.json ├── staticfiles.csproj ├── tmp.tar └── wwwroot │ └── index.html ├── 15-nativeaot-net7 ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json ├── appsettings.json ├── global.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 16-distroless-net8-aggressivetrim ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json ├── appsettings.json ├── global.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 2-default ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 3-focal ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 4-alpine12 ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 5-alpine13 ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 6-busterslim ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 7-runtimedeps ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj └── wwwroot │ └── index.html ├── 8-distroless ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj ├── tmp.tar └── wwwroot │ └── index.html ├── 9-distroless2 ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj ├── tmp.tar └── wwwroot │ └── index.html ├── README.md ├── alpine-distroless └── Dockerfile ├── build.ps1 ├── final-aspnet ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj ├── tmp.tar └── wwwroot │ └── index.html ├── final-net6 ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj ├── tmp.tar └── wwwroot │ └── index.html ├── final ├── Dockerfile ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── staticfiles.csproj ├── tmp.tar └── wwwroot │ └── index.html └── global.json /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Nuget personal access tokens and Credentials 210 | nuget.config 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio LightSwitch build output 301 | **/*.HTMLClient/GeneratedArtifacts 302 | **/*.DesktopClient/GeneratedArtifacts 303 | **/*.DesktopClient/ModelManifest.xml 304 | **/*.Server/GeneratedArtifacts 305 | **/*.Server/ModelManifest.xml 306 | _Pvt_Extensions 307 | 308 | # Paket dependency manager 309 | .paket/paket.exe 310 | paket-files/ 311 | 312 | # FAKE - F# Make 313 | .fake/ 314 | 315 | # CodeRush personal settings 316 | .cr/personal 317 | 318 | # Python Tools for Visual Studio (PTVS) 319 | __pycache__/ 320 | *.pyc 321 | 322 | # Cake - Uncomment if you are using it 323 | # tools/** 324 | # !tools/packages.config 325 | 326 | # Tabs Studio 327 | *.tss 328 | 329 | # Telerik's JustMock configuration file 330 | *.jmconfig 331 | 332 | # BizTalk build output 333 | *.btp.cs 334 | *.btm.cs 335 | *.odx.cs 336 | *.xsd.cs 337 | 338 | # OpenCover UI analysis results 339 | OpenCover/ 340 | 341 | # Azure Stream Analytics local run output 342 | ASALocalRun/ 343 | 344 | # MSBuild Binary and Structured Log 345 | *.binlog 346 | 347 | # NVidia Nsight GPU debugger configuration file 348 | *.nvuser 349 | 350 | # MFractors (Xamarin productivity tool) working folder 351 | .mfractor/ 352 | 353 | # Local History for Visual Studio 354 | .localhistory/ 355 | 356 | # BeatPulse healthcheck temp database 357 | healthchecksdb 358 | 359 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 360 | MigrationBackup/ 361 | 362 | # Ionide (cross platform F# VS Code tools) working folder 363 | .ionide/ 364 | 365 | # Fody - auto-generated XML schema 366 | FodyWeavers.xsd 367 | 368 | # VS Code files for those working on multiple tools 369 | .vscode/* 370 | !.vscode/settings.json 371 | !.vscode/tasks.json 372 | !.vscode/launch.json 373 | !.vscode/extensions.json 374 | *.code-workspace 375 | 376 | # Local History for Visual Studio Code 377 | .history/ 378 | 379 | # Windows Installer files from build outputs 380 | *.cab 381 | *.msi 382 | *.msix 383 | *.msm 384 | *.msp 385 | 386 | # JetBrains Rider 387 | .idea/ 388 | *.sln.iml -------------------------------------------------------------------------------- /1-nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:1.21.3 2 | COPY wwwroot /usr/share/nginx/html 3 | -------------------------------------------------------------------------------- /1-nginx/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

1. Baseline Nginx

9 | 10 | -------------------------------------------------------------------------------- /10-bullseyeslim-net6/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build-env 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | RUN dotnet restore 7 | 8 | # Copy everything else and build 9 | COPY . . 10 | RUN dotnet publish -c Release -o out 11 | 12 | # Build runtime image 13 | FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim 14 | WORKDIR /app 15 | COPY --from=build-env /app/out . 16 | ENTRYPOINT ["dotnet", "staticfiles.dll"] 17 | -------------------------------------------------------------------------------- /10-bullseyeslim-net6/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | var app = builder.Build(); 6 | 7 | if (app.Environment.IsDevelopment()) 8 | { 9 | app.UseDeveloperExceptionPage(); 10 | } 11 | 12 | app.UseFileServer(); 13 | 14 | app.UseRouting(); 15 | 16 | app.Run(); 17 | -------------------------------------------------------------------------------- /10-bullseyeslim-net6/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /10-bullseyeslim-net6/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /10-bullseyeslim-net6/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /10-bullseyeslim-net6/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /10-bullseyeslim-net6/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Buster Slim

9 | 10 | -------------------------------------------------------------------------------- /11-runtimedeps-net6/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | RUN dotnet restore 7 | 8 | # Copy everything else and build 9 | COPY . . 10 | RUN dotnet publish \ 11 | --runtime alpine-x64 \ 12 | --self-contained true \ 13 | /p:PublishTrimmed=true \ 14 | /p:PublishSingleFile=true \ 15 | -c Release \ 16 | -o out 17 | 18 | # Build runtime image 19 | FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-alpine3.13-amd64 20 | WORKDIR /app 21 | COPY --from=build-env /app/out . 22 | ENV DOTNET_RUNNING_IN_CONTAINER=true \ 23 | ASPNETCORE_URLS=http://+:80 24 | EXPOSE 80 25 | ENTRYPOINT ["./staticfiles"] -------------------------------------------------------------------------------- /11-runtimedeps-net6/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | var app = builder.Build(); 6 | 7 | if (app.Environment.IsDevelopment()) 8 | { 9 | app.UseDeveloperExceptionPage(); 10 | } 11 | 12 | app.UseFileServer(); 13 | 14 | app.UseRouting(); 15 | 16 | app.Run(); 17 | -------------------------------------------------------------------------------- /11-runtimedeps-net6/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /11-runtimedeps-net6/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /11-runtimedeps-net6/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /11-runtimedeps-net6/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /11-runtimedeps-net6/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Runtime Deps - Alpine 3.13

9 | 10 | -------------------------------------------------------------------------------- /12-distroless2-net6/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use dotnet runtime deps to gather all dependencies 2 | FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-alpine3.13-amd64 as base 3 | 4 | # Cleanup /lib 5 | RUN find /lib -type d -empty -delete && \ 6 | rm -r /lib/apk && \ 7 | rm -r /lib/sysctl.d 8 | 9 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env 10 | WORKDIR /app 11 | 12 | # Copy csproj and restore as distinct layers 13 | COPY *.csproj ./ 14 | RUN dotnet restore 15 | 16 | # Copy everything else and build 17 | COPY . . 18 | RUN dotnet publish \ 19 | --runtime alpine-x64 \ 20 | --self-contained true \ 21 | /p:PublishTrimmed=true \ 22 | /p:PublishSingleFile=true \ 23 | -c Release \ 24 | -o out 25 | 26 | # Create runtime image 27 | FROM scratch 28 | COPY --from=base /lib/ /lib 29 | COPY --from=base /usr/lib /usr/lib 30 | COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt 31 | 32 | # chmod hack: extract tmp.tar file with correct flags 33 | # see https://github.com/GoogleContainerTools/distroless/blob/main/base/tmp.tar 34 | ADD tmp.tar . 35 | 36 | ENV ASPNETCORE_URLS=http://+:80 \ 37 | DOTNET_RUNNING_IN_CONTAINER=true \ 38 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true 39 | 40 | WORKDIR /app 41 | COPY --from=build-env --chown=1111:1111 /app/out ./ 42 | 43 | EXPOSE 80 44 | ENTRYPOINT ["./staticfiles"] -------------------------------------------------------------------------------- /12-distroless2-net6/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | var app = builder.Build(); 6 | 7 | if (app.Environment.IsDevelopment()) 8 | { 9 | app.UseDeveloperExceptionPage(); 10 | } 11 | 12 | app.UseFileServer(); 13 | 14 | app.UseRouting(); 15 | 16 | app.Run(); 17 | -------------------------------------------------------------------------------- /12-distroless2-net6/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /12-distroless2-net6/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /12-distroless2-net6/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /12-distroless2-net6/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /12-distroless2-net6/tmp.tar: -------------------------------------------------------------------------------- 1 | tmp/0001777000000000000000000000000013140662635010367 5ustar rootroot -------------------------------------------------------------------------------- /12-distroless2-net6/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Distroless (take 2)

9 | 10 | -------------------------------------------------------------------------------- /12a-distroless2-net6-aggressivetrim/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use dotnet runtime deps to gather all dependencies 2 | FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-alpine3.13-amd64 as base 3 | 4 | # Cleanup /lib 5 | RUN find /lib -type d -empty -delete && \ 6 | rm -r /lib/apk && \ 7 | rm -r /lib/sysctl.d 8 | 9 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env 10 | WORKDIR /app 11 | 12 | # Copy csproj and restore as distinct layers 13 | COPY *.csproj ./ 14 | RUN dotnet restore 15 | 16 | # Copy everything else and build 17 | COPY . . 18 | RUN dotnet publish \ 19 | --runtime alpine-x64 \ 20 | --self-contained true \ 21 | /p:PublishSingleFile=true \ 22 | -c Release \ 23 | -o out 24 | 25 | # Create runtime image 26 | FROM scratch 27 | COPY --from=base /lib/ /lib 28 | COPY --from=base /usr/lib /usr/lib 29 | COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt 30 | 31 | # chmod hack: extract tmp.tar file with correct flags 32 | # see https://github.com/GoogleContainerTools/distroless/blob/main/base/tmp.tar 33 | ADD tmp.tar . 34 | 35 | ENV ASPNETCORE_URLS=http://+:80 \ 36 | DOTNET_RUNNING_IN_CONTAINER=true \ 37 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true 38 | 39 | WORKDIR /app 40 | COPY --from=build-env --chown=1111:1111 /app/out ./ 41 | 42 | EXPOSE 80 43 | ENTRYPOINT ["./staticfiles"] -------------------------------------------------------------------------------- /12a-distroless2-net6-aggressivetrim/Program.cs: -------------------------------------------------------------------------------- 1 | var hostBuilder = Host.CreateDefaultBuilder(args) 2 | .ConfigureWebHostDefaults(webBuilder => 3 | { 4 | webBuilder.Configure((ctx, app) => 5 | { 6 | app.UseStaticFiles(); 7 | app.UseRouting(); 8 | }); 9 | }); 10 | 11 | hostBuilder.Build().Run(); 12 | -------------------------------------------------------------------------------- /12a-distroless2-net6-aggressivetrim/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /12a-distroless2-net6-aggressivetrim/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /12a-distroless2-net6-aggressivetrim/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /12a-distroless2-net6-aggressivetrim/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | 7 | 8 | true 9 | 10 | 11 | true 12 | link 13 | true 14 | false 15 | false 16 | false 17 | false 18 | true 19 | false 20 | true 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /12a-distroless2-net6-aggressivetrim/tmp.tar: -------------------------------------------------------------------------------- 1 | tmp/0001777000000000000000000000000013140662635010367 5ustar rootroot -------------------------------------------------------------------------------- /12a-distroless2-net6-aggressivetrim/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Distroless (take 2)

9 | 10 | -------------------------------------------------------------------------------- /13-bullseyeslim-net7/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build-env 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | RUN dotnet restore 7 | 8 | # Copy everything else and build 9 | COPY . . 10 | RUN dotnet publish -c Release -o out 11 | 12 | # Build runtime image 13 | FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim 14 | WORKDIR /app 15 | COPY --from=build-env /app/out . 16 | ENTRYPOINT ["dotnet", "staticfiles.dll"] 17 | -------------------------------------------------------------------------------- /13-bullseyeslim-net7/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | var app = builder.Build(); 6 | 7 | if (app.Environment.IsDevelopment()) 8 | { 9 | app.UseDeveloperExceptionPage(); 10 | } 11 | 12 | app.UseFileServer(); 13 | 14 | app.UseRouting(); 15 | 16 | app.Run(); 17 | -------------------------------------------------------------------------------- /13-bullseyeslim-net7/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /13-bullseyeslim-net7/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /13-bullseyeslim-net7/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /13-bullseyeslim-net7/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /13-bullseyeslim-net7/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

2 - .NET 5 Default

9 | 10 | -------------------------------------------------------------------------------- /14-distroless-net7-aggressivetrim/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use dotnet runtime deps to gather all dependencies 2 | FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-amd64 as base 3 | 4 | # Cleanup /lib 5 | RUN find /lib -type d -empty -delete && \ 6 | rm -r /lib/apk && \ 7 | rm -r /lib/sysctl.d 8 | 9 | FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine-amd64 AS build-env 10 | WORKDIR /app 11 | 12 | # Copy csproj and restore as distinct layers 13 | COPY *.csproj ./ 14 | COPY global.json ./ 15 | RUN dotnet restore 16 | 17 | # Copy everything else and build 18 | COPY . . 19 | RUN dotnet publish \ 20 | --runtime alpine-x64 \ 21 | --self-contained true \ 22 | /p:PublishSingleFile=true \ 23 | -c Release \ 24 | -o out 25 | 26 | # Create runtime image 27 | FROM scratch 28 | COPY --from=base /lib/ /lib 29 | COPY --from=base /usr/lib /usr/lib 30 | COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt 31 | 32 | # chmod hack: extract tmp.tar file with correct flags 33 | # see https://github.com/GoogleContainerTools/distroless/blob/main/base/tmp.tar 34 | ADD tmp.tar . 35 | 36 | ENV ASPNETCORE_URLS=http://+:80 \ 37 | DOTNET_RUNNING_IN_CONTAINER=true \ 38 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true 39 | 40 | WORKDIR /app 41 | COPY --from=build-env --chown=1111:1111 /app/out ./ 42 | 43 | EXPOSE 80 44 | ENTRYPOINT ["./staticfiles"] -------------------------------------------------------------------------------- /14-distroless-net7-aggressivetrim/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | var app = builder.Build(); 6 | 7 | app.UseFileServer(); 8 | 9 | app.UseRouting(); 10 | 11 | app.Run(); 12 | -------------------------------------------------------------------------------- /14-distroless-net7-aggressivetrim/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /14-distroless-net7-aggressivetrim/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /14-distroless-net7-aggressivetrim/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /14-distroless-net7-aggressivetrim/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "7.0.100-preview.4.22252.9" 4 | } 5 | } -------------------------------------------------------------------------------- /14-distroless-net7-aggressivetrim/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | 7 | 8 | true 9 | 10 | 11 | true 12 | link 13 | true 14 | false 15 | false 16 | false 17 | false 18 | true 19 | false 20 | true 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /14-distroless-net7-aggressivetrim/tmp.tar: -------------------------------------------------------------------------------- 1 | tmp/0001777000000000000000000000000013140662635010367 5ustar rootroot -------------------------------------------------------------------------------- /14-distroless-net7-aggressivetrim/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

2 - .NET 5 Default

9 | 10 | -------------------------------------------------------------------------------- /15-nativeaot-net7/Dockerfile: -------------------------------------------------------------------------------- 1 | # Build image for Native AOT 2 | FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build-env 3 | 4 | # Ensure we install clang for Native AOT to work (there may be extra libraries being installed here but... it works and these never make it to the final image) 5 | RUN apt-get update && \ 6 | apt-get -y install clang zlib1g-dev 7 | 8 | WORKDIR /app 9 | 10 | # Copy csproj and restore as distinct layers 11 | COPY *.csproj ./ 12 | COPY global.json ./ 13 | COPY ./nuget.config ./ 14 | RUN dotnet restore 15 | 16 | # Copy everything else and build 17 | COPY . . 18 | RUN dotnet publish \ 19 | --runtime linux-x64 \ 20 | --self-contained true \ 21 | -c Release \ 22 | -o out 23 | 24 | # Smallest distroless with the dependencies 25 | FROM gcr.io/distroless/cc 26 | COPY --from=build-env /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu 27 | 28 | # Add the NativeAOT application 29 | ENV ASPNETCORE_URLS=http://+:80 \ 30 | DOTNET_RUNNING_IN_CONTAINER=true \ 31 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true 32 | 33 | WORKDIR /app 34 | COPY --from=build-env --chown=1111:1111 /app/out/staticfiles ./staticfiles 35 | COPY --from=build-env --chown=1111:1111 /app/out/wwwroot ./wwwroot 36 | 37 | EXPOSE 80 38 | CMD ["./staticfiles"] 39 | -------------------------------------------------------------------------------- /15-nativeaot-net7/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | var app = builder.Build(); 6 | 7 | app.UseFileServer(); 8 | 9 | app.UseRouting(); 10 | 11 | app.Run(); 12 | -------------------------------------------------------------------------------- /15-nativeaot-net7/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /15-nativeaot-net7/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /15-nativeaot-net7/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /15-nativeaot-net7/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "7.0.100-preview.4.22252.9" 4 | } 5 | } -------------------------------------------------------------------------------- /15-nativeaot-net7/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | enable 7 | 8 | 9 | true 10 | true 11 | false 12 | false 13 | false 14 | false 15 | true 16 | false 17 | true 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /15-nativeaot-net7/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

2 - .NET 5 Default

9 | 10 | -------------------------------------------------------------------------------- /16-distroless-net8-aggressivetrim/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:8.0.100-preview.2-alpine3.17-amd64 AS build-env 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | COPY global.json ./ 7 | RUN dotnet restore 8 | 9 | # Copy everything else and build 10 | COPY . . 11 | RUN dotnet publish \ 12 | --runtime alpine-x64 \ 13 | --self-contained true \ 14 | /p:PublishSingleFile=true \ 15 | -c Release \ 16 | -o out 17 | 18 | # Use dotnet runtime deps to gather all dependencies 19 | FROM mcr.microsoft.com/dotnet/runtime-deps:8.0.0-preview.2-alpine3.17-amd64 as base 20 | 21 | # Cleanup /lib 22 | RUN find /lib -type d -empty -delete && \ 23 | rm -r /lib/apk && \ 24 | rm -r /lib/sysctl.d 25 | 26 | # Create runtime image 27 | FROM scratch 28 | COPY --from=base /lib/ /lib 29 | COPY --from=base /usr/lib /usr/lib 30 | COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt 31 | COPY --from=base /tmp/ /tmp 32 | 33 | ENV \ 34 | # Configure web servers to bind to port 8080 when present 35 | ASPNETCORE_HTTP_PORTS=8080 \ 36 | # Enable detection of running in a container 37 | DOTNET_RUNNING_IN_CONTAINER=true \ 38 | # Set the invariant mode since ICU package isn't included (see https://github.com/dotnet/announcements/issues/20) 39 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true 40 | 41 | WORKDIR /app 42 | COPY --from=build-env --chown=1111:1111 /app/out ./ 43 | 44 | EXPOSE 8080 45 | ENTRYPOINT ["./staticfiles"] 46 | -------------------------------------------------------------------------------- /16-distroless-net8-aggressivetrim/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | var app = builder.Build(); 6 | 7 | app.UseFileServer(); 8 | 9 | app.UseRouting(); 10 | 11 | app.Run(); 12 | -------------------------------------------------------------------------------- /16-distroless-net8-aggressivetrim/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /16-distroless-net8-aggressivetrim/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /16-distroless-net8-aggressivetrim/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /16-distroless-net8-aggressivetrim/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "8.0.100-preview.2", 4 | "rollForward": "latestFeature" 5 | } 6 | } -------------------------------------------------------------------------------- /16-distroless-net8-aggressivetrim/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | 7 | 8 | true 9 | 10 | 11 | true 12 | link 13 | true 14 | false 15 | false 16 | false 17 | false 18 | true 19 | false 20 | true 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /16-distroless-net8-aggressivetrim/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

16 - .NET 8 Chiseled Alpine

9 | 10 | -------------------------------------------------------------------------------- /2-default/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | RUN dotnet restore 7 | 8 | # Copy everything else and build 9 | COPY . . 10 | RUN dotnet publish -c Release -o out 11 | 12 | # Build runtime image 13 | FROM mcr.microsoft.com/dotnet/aspnet:5.0.5 14 | WORKDIR /app 15 | COPY --from=build-env /app/out . 16 | ENTRYPOINT ["dotnet", "staticfiles.dll"] 17 | -------------------------------------------------------------------------------- /2-default/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Dpb.StaticFiles 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /2-default/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /2-default/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace Dpb.StaticFiles 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | } 20 | 21 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseFileServer(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => {}); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /2-default/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /2-default/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /2-default/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /2-default/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

2 - .NET 5 Default

9 | 10 | -------------------------------------------------------------------------------- /3-focal/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | RUN dotnet restore 7 | 8 | # Copy everything else and build 9 | COPY . . 10 | RUN dotnet publish -c Release -o out 11 | 12 | # Build runtime image 13 | FROM mcr.microsoft.com/dotnet/aspnet:5.0.5-focal 14 | WORKDIR /app 15 | COPY --from=build-env /app/out . 16 | ENTRYPOINT ["dotnet", "staticfiles.dll"] 17 | -------------------------------------------------------------------------------- /3-focal/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Dpb.StaticFiles 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /3-focal/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /3-focal/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace Dpb.StaticFiles 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | } 20 | 21 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseFileServer(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => {}); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /3-focal/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /3-focal/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /3-focal/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /3-focal/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Focal

9 | 10 | -------------------------------------------------------------------------------- /4-alpine12/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | RUN dotnet restore 7 | 8 | # Copy everything else and build 9 | COPY . . 10 | RUN dotnet publish -c Release -o out 11 | 12 | # Build runtime image 13 | FROM mcr.microsoft.com/dotnet/aspnet:5.0.5-alpine3.12-amd64 14 | WORKDIR /app 15 | COPY --from=build-env /app/out . 16 | ENTRYPOINT ["dotnet", "staticfiles.dll"] 17 | -------------------------------------------------------------------------------- /4-alpine12/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Dpb.StaticFiles 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /4-alpine12/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /4-alpine12/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace Dpb.StaticFiles 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | } 20 | 21 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseFileServer(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => {}); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /4-alpine12/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /4-alpine12/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /4-alpine12/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /4-alpine12/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Alpine 3.12

9 | 10 | -------------------------------------------------------------------------------- /5-alpine13/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | RUN dotnet restore 7 | 8 | # Copy everything else and build 9 | COPY . . 10 | RUN dotnet publish -c Release -o out 11 | 12 | # Build runtime image 13 | FROM mcr.microsoft.com/dotnet/aspnet:5.0.5-alpine3.13-amd64 14 | WORKDIR /app 15 | COPY --from=build-env /app/out . 16 | ENTRYPOINT ["dotnet", "staticfiles.dll"] 17 | -------------------------------------------------------------------------------- /5-alpine13/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Dpb.StaticFiles 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /5-alpine13/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /5-alpine13/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace Dpb.StaticFiles 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | } 20 | 21 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseFileServer(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => {}); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /5-alpine13/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /5-alpine13/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /5-alpine13/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /5-alpine13/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Alpine 3.13

9 | 10 | -------------------------------------------------------------------------------- /6-busterslim/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | RUN dotnet restore 7 | 8 | # Copy everything else and build 9 | COPY . . 10 | RUN dotnet publish -c Release -o out 11 | 12 | # Build runtime image 13 | FROM mcr.microsoft.com/dotnet/aspnet:5.0.5-buster-slim 14 | WORKDIR /app 15 | COPY --from=build-env /app/out . 16 | ENTRYPOINT ["dotnet", "staticfiles.dll"] 17 | -------------------------------------------------------------------------------- /6-busterslim/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Dpb.StaticFiles 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /6-busterslim/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /6-busterslim/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace Dpb.StaticFiles 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | } 20 | 21 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseFileServer(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => {}); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /6-busterslim/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /6-busterslim/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /6-busterslim/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /6-busterslim/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Buster Slim

9 | 10 | -------------------------------------------------------------------------------- /7-runtimedeps/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 2 | WORKDIR /app 3 | 4 | # Copy csproj and restore as distinct layers 5 | COPY *.csproj ./ 6 | RUN dotnet restore 7 | 8 | # Copy everything else and build 9 | COPY . . 10 | RUN dotnet publish \ 11 | --runtime alpine-x64 \ 12 | --self-contained true \ 13 | /p:PublishTrimmed=true \ 14 | /p:PublishSingleFile=true \ 15 | -c Release \ 16 | -o out 17 | 18 | # Build runtime image 19 | FROM mcr.microsoft.com/dotnet/runtime-deps:5.0.5-alpine3.13-amd64 20 | WORKDIR /app 21 | COPY --from=build-env /app/out . 22 | ENV DOTNET_RUNNING_IN_CONTAINER=true \ 23 | ASPNETCORE_URLS=http://+:80 24 | EXPOSE 80 25 | ENTRYPOINT ["./staticfiles"] -------------------------------------------------------------------------------- /7-runtimedeps/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Dpb.StaticFiles 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /7-runtimedeps/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /7-runtimedeps/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace Dpb.StaticFiles 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | } 20 | 21 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseFileServer(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => {}); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /7-runtimedeps/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /7-runtimedeps/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /7-runtimedeps/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /7-runtimedeps/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Runtime Deps - Alpine 3.13

9 | 10 | -------------------------------------------------------------------------------- /8-distroless/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use alpine to gather all dependencies 2 | FROM alpine:3.13 as base 3 | 4 | RUN apk add --no-cache icu-libs \ 5 | krb5-libs \ 6 | libgcc \ 7 | libintl \ 8 | libssl1.1 \ 9 | libstdc++ \ 10 | zlib \ 11 | ca-certificates && update-ca-certificates 12 | 13 | # Cleanup /lib 14 | RUN find /lib -type d -empty -delete && \ 15 | rm -r /lib/apk && \ 16 | rm -r /lib/sysctl.d 17 | 18 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 19 | WORKDIR /app 20 | 21 | # Copy csproj and restore as distinct layers 22 | COPY *.csproj ./ 23 | RUN dotnet restore 24 | 25 | # Copy everything else and build 26 | COPY . . 27 | RUN dotnet publish \ 28 | --runtime alpine-x64 \ 29 | --self-contained true \ 30 | /p:PublishTrimmed=true \ 31 | /p:PublishSingleFile=true \ 32 | -c Release \ 33 | -o out 34 | 35 | # Create runtime image 36 | FROM scratch 37 | COPY --from=base /lib/ /lib 38 | COPY --from=base /usr/lib /usr/lib 39 | COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt 40 | 41 | # chmod hack: extract tmp.tar file with correct flags 42 | # see https://github.com/GoogleContainerTools/distroless/blob/main/base/tmp.tar 43 | ADD tmp.tar . 44 | 45 | ENV ASPNETCORE_URLS=http://+:80 \ 46 | DOTNET_RUNNING_IN_CONTAINER=true \ 47 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true 48 | 49 | WORKDIR /app 50 | COPY --from=build-env --chown=1111:1111 /app/out ./ 51 | 52 | EXPOSE 80 53 | ENTRYPOINT ["./staticfiles"] -------------------------------------------------------------------------------- /8-distroless/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Dpb.StaticFiles 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /8-distroless/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /8-distroless/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace Dpb.StaticFiles 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | } 20 | 21 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseFileServer(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => {}); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /8-distroless/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /8-distroless/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /8-distroless/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /8-distroless/tmp.tar: -------------------------------------------------------------------------------- 1 | tmp/0001777000000000000000000000000013140662635010367 5ustar rootroot -------------------------------------------------------------------------------- /8-distroless/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Alpine 3.14 Distroless

9 | 10 | -------------------------------------------------------------------------------- /9-distroless2/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use dotnet runtime deps to gather all dependencies 2 | FROM mcr.microsoft.com/dotnet/runtime-deps:5.0.5-alpine3.13-amd64 as base 3 | 4 | # Cleanup /lib 5 | RUN find /lib -type d -empty -delete && \ 6 | rm -r /lib/apk && \ 7 | rm -r /lib/sysctl.d 8 | 9 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 10 | WORKDIR /app 11 | 12 | # Copy csproj and restore as distinct layers 13 | COPY *.csproj ./ 14 | RUN dotnet restore 15 | 16 | # Copy everything else and build 17 | COPY . . 18 | RUN dotnet publish \ 19 | --runtime alpine-x64 \ 20 | --self-contained true \ 21 | /p:PublishTrimmed=true \ 22 | /p:PublishSingleFile=true \ 23 | -c Release \ 24 | -o out 25 | 26 | # Create runtime image 27 | FROM scratch 28 | COPY --from=base /lib/ /lib 29 | COPY --from=base /usr/lib /usr/lib 30 | COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt 31 | 32 | # chmod hack: extract tmp.tar file with correct flags 33 | # see https://github.com/GoogleContainerTools/distroless/blob/main/base/tmp.tar 34 | ADD tmp.tar . 35 | 36 | ENV ASPNETCORE_URLS=http://+:80 \ 37 | DOTNET_RUNNING_IN_CONTAINER=true \ 38 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true 39 | 40 | WORKDIR /app 41 | COPY --from=build-env --chown=1111:1111 /app/out ./ 42 | 43 | EXPOSE 80 44 | ENTRYPOINT ["./staticfiles"] -------------------------------------------------------------------------------- /9-distroless2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Dpb.StaticFiles 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /9-distroless2/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /9-distroless2/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace Dpb.StaticFiles 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | } 20 | 21 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseFileServer(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => {}); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /9-distroless2/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /9-distroless2/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /9-distroless2/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /9-distroless2/tmp.tar: -------------------------------------------------------------------------------- 1 | tmp/0001777000000000000000000000000013140662635010367 5ustar rootroot -------------------------------------------------------------------------------- /9-distroless2/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

3 - .NET 5 Distroless (take 2)

9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # .NET Static Files - Docker Image Sizes 2 | 3 | **UPDATED FOR .NET 8.0 IMAGES and "Chiseled Alpine"** 4 | 5 | ## Chiseled vs Alpine images 6 | 7 | Microsoft and Ubuntu have done some great work recently on reducing image sizes, especially the [Runtime Deps](https://hub.docker.com/_/microsoft-dotnet-runtime-deps/) image. 8 | 9 | The latest 8.0 preview tags come in as: 10 | | Tag | Size | 11 | |---|---| 12 | | 8.0.0-preview.2-alpine3.17-amd64 | 12.2MB | 13 | | 8.0.0-preview.2-bookworm-slim-amd64 | 123MB | 14 | | 8.0.0-preview.2-jammy-chiseled-amd64 | 13MB | 15 | 16 | I was still working under the assumption that Chiseled would be smaller than Alpine. But an exchange with Damian Edwards highlighted this not to be the case: https://twitter.com/DamianEdwards/status/1644473764665761792?s=20. The difference seems to come down to the Jammy Chiseled image being based on Ubuntu (and using glibc), whereas Alpine ships with musl. 17 | 18 | Personally, I don't like having package managers in my runtime images, so I set about to remove some of that from the Alpine image. The result can be seen in what I'm calling ["Chiseled Alpine"](./alpine-distroless/Dockerfile). 19 | 20 | This reduces the 12.2MB Alpine image down to *10.4MB* (and yes, it does still work). 21 | 22 | So I've updated the table below to include a .NET 8-based app. 23 | 24 | ## Docker Commands 25 | 26 | See the `build.ps1` script for the commands used to generate these images. 27 | 28 | For the first nine images (everything except for "final"), run this command from the root. 29 | 30 | ``` 31 | ./build.ps1 -name {foldername} 32 | ``` 33 | 34 | If you want to build the "final" image, run the command: 35 | ``` 36 | ./build.ps1 -name {foldername} -port 8080 37 | ``` 38 | 39 | Why is the last one different? Because I've further hardened the image by running on a port that doesn't require root access. 40 | 41 | ## Results 42 | 43 | | Image|.NET Version|.NET App Publish Approach|Size| 44 | |---|---|---|---| 45 | | 1 | N/A | N/A - **Nginx** | 133MB | 46 | | 2 | .NET 5.0.5 | Framework-Dependent, default Docker tag | 206MB | 47 | | 3 | .NET 5.0.5 | Framework-Dependent, Focal image | 213MB | 48 | | 4 | .NET 5.0.5 | Framework-Dependent, Alpine 3.12 image | 103MB | 49 | | 5 | .NET 5.0.5 | Framework-Dependent, Alpine 3.13 image | 103MB | 50 | | 6 | .NET 5.0.5 | Framework-Dependent, Buster Slim image | 206MB | 51 | | 7 | .NET 5.0.5 | Self-Contained, [Runtime Deps](https://hub.docker.com/_/microsoft-dotnet-runtime-deps/) image | 50.2MB | 52 | | 8 | .NET 5.0.5 | Self-Contained, Distroless TAKE ONE (Alpine 3.13) | 81.5MB | 53 | | 9 | .NET 5.0.5 | Self-Contained, Distroless TAKE TWO (Runtime Deps) | 48.4MB | 54 | | 10 | .NET 6.0 | Framework-Dependent, Bullseye Slim image | 208MB | 55 | | 11 | .NET 6.0 | Self-Contained, [Runtime Deps](https://hub.docker.com/_/microsoft-dotnet-runtime-deps/) image | 50.1MB | 56 | | 12 | .NET 6.0 | Self-Contained, Trimmed, Distroless (Runtime Deps) | 46.4MB | 57 | | 13 | .NET 7.0 | Framework-Dependent, Bullseye Slim image | 209MB | 58 | | 14 | .NET 7.0 | Self-Contained, Trimmed, [Runtime Deps](https://hub.docker.com/_/microsoft-dotnet-runtime-deps/) image | 38.9MB | 59 | | 15 | .NET 7.0 | **NativeAOT**, [GCR Distroless CC](https://github.com/GoogleContainerTools/distroless/tree/main/cc) image | 120MB | 60 | | 16 | **.NET 8.0** | Self-Contained, **Trimmed**, "Chiseled" alpine image based on [Runtime Deps](https://hub.docker.com/_/microsoft-dotnet-runtime-deps/) image | **28.3MB** | 61 | 62 | ## So I should use Self-Contained then, right? 63 | 64 | As always... it depends. 65 | 66 | Take a second to read this article by Andrew Lock on the topic https://andrewlock.net/should-i-use-self-contained-or-framework-dependent-publishing-in-docker-images/. 67 | 68 | The summary at the end goes to explain about how Docker caches layers. So if you have multiple images using the same layers, then you will likely see benefit from caching layers. 69 | 70 | Here's the recreation of the table from Andrew's post with the new information: 71 | 72 | | Layer | Cached? | Framework-dependent | Self-contained | 73 | |---|---|---|---| 74 | | Base runtime dependencies | Yes | 8.4MB | 8.4MB | 75 | | Shared framework layer| Yes | 93MB | - | 76 | | Application DLLs| No | 269KB | 40MB | 77 | | Total | | 102.4MB | 48.4MB | 78 | | Total (excluding cached)| | 269kB | 40MB | 79 | 80 | Obviously, the test application here is really simple and the difference between loading 269kB vs 40MB on modern hardware is probably minimal. So, deciding between Framework-dependent or Self-contained will largely depend on your circumstances. 81 | 82 | However, I can strongly recomment going Distroless... 83 | 84 | ## Why Distroless? 85 | 86 | Don't listen to me, listen to these guys... 87 | - https://github.com/GoogleContainerTools/distroless 88 | - https://cloud.redhat.com/blog/hardening-docker-containers-images-and-host-security-toolkit 89 | 90 | The TL;DR; is that distroless images only contain YOUR application and its dependencies. No shells such as bash, sh, etc. 91 | 92 | ## Examing the images 93 | 94 | You can explore any of these images (once you build them locally) using the fantastic "Dive" app. See https://github.com/wagoodman/dive. 95 | 96 | Run the command: 97 | ``` 98 | dive dpbevin/staticfiles-9-distroless2 99 | ``` 100 | 101 | ## References 102 | 103 | - https://github.com/dotnet/dotnet-docker/issues/2074 104 | - https://ariadne.space/2021/09/09/introducing-witchery-tools-for-building-distroless-images-with-alpine/ 105 | - https://itnext.io/smaller-docker-images-for-asp-net-core-apps-bee4a8fd1277 106 | - https://medium.com/01001101/containerize-your-net-core-app-the-right-way-35c267224a8d 107 | - https://techcommunity.microsoft.com/t5/azure-developer-community-blog/hardening-an-asp-net-container-running-on-kubernetes/ba-p/2542224 -------------------------------------------------------------------------------- /alpine-distroless/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use dotnet runtime deps to gather all dependencies 2 | FROM mcr.microsoft.com/dotnet/runtime-deps:8.0.0-preview.2-alpine3.17-amd64 as base 3 | 4 | # Cleanup /lib 5 | RUN find /lib -type d -empty -delete && \ 6 | rm -r /lib/apk && \ 7 | rm -r /lib/sysctl.d 8 | 9 | # Create runtime image 10 | FROM scratch 11 | COPY --from=base /lib/ /lib 12 | COPY --from=base /usr/lib /usr/lib 13 | COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt 14 | COPY --from=base /tmp/ /tmp 15 | 16 | ENV \ 17 | # Configure web servers to bind to port 8080 when present 18 | ASPNETCORE_HTTP_PORTS=8080 \ 19 | # Enable detection of running in a container 20 | DOTNET_RUNNING_IN_CONTAINER=true \ 21 | # Set the invariant mode since ICU package isn't included (see https://github.com/dotnet/announcements/issues/20) 22 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true 23 | -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env pwsh 2 | param ( 3 | [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] 4 | [string]$name, 5 | 6 | [Parameter(Mandatory = $false)] 7 | [string]$port = "80" 8 | ) 9 | 10 | Push-Location 11 | Set-Location $name 12 | 13 | try 14 | { 15 | & docker build -t dpbevin/staticfiles-$name . 16 | $size = (& docker images --format "{{upper .Size}}" dpbevin/staticfiles-$name) 17 | $dockerId = (& docker run --rm -d -p 8088:$port dpbevin/staticfiles-$name) 18 | Start-Sleep -Seconds 5 19 | $iwrResult = Invoke-WebRequest http://localhost:8088 20 | & docker stop $dockerId 21 | 22 | Write-Host 23 | if ($iwrResult.StatusCode -eq 200) { 24 | Write-Host `Image dpbevin/staticfiles-$name is $size` 25 | } else { 26 | Write-Host "Failed to respond" 27 | } 28 | } 29 | finally 30 | { 31 | Pop-Location 32 | } 33 | -------------------------------------------------------------------------------- /final-aspnet/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use dotnet runtime deps to gather all dependencies 2 | FROM mcr.microsoft.com/dotnet/aspnet:5.0.10-alpine3.14-amd64 as base 3 | 4 | # Cleanup /lib 5 | RUN find /lib -type d -empty -delete && \ 6 | rm -r /lib/apk && \ 7 | rm -r /lib/sysctl.d 8 | 9 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 10 | WORKDIR /app 11 | 12 | # Copy csproj and restore as distinct layers 13 | COPY *.csproj ./ 14 | RUN dotnet restore 15 | 16 | # Copy everything else and build 17 | COPY . . 18 | RUN dotnet publish \ 19 | -c Release \ 20 | -o out 21 | 22 | # Create runtime image 23 | FROM scratch 24 | COPY --from=base /lib/ /lib 25 | COPY --from=base /usr/lib /usr/lib 26 | COPY --from=base /usr/share/dotnet /usr/share/dotnet 27 | COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt 28 | 29 | # chmod hack: extract tmp.tar file with correct flags 30 | # see https://github.com/GoogleContainerTools/distroless/blob/main/base/tmp.tar 31 | ADD tmp.tar . 32 | 33 | ENV ASPNETCORE_URLS=http://+:8080 \ 34 | DOTNET_RUNNING_IN_CONTAINER=true \ 35 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true \ 36 | COMPlus_EnableDiagnostics=0 37 | 38 | WORKDIR /app 39 | COPY --from=build-env --chown=1111:1111 /app/out ./ 40 | USER 1111:1111 41 | EXPOSE 8080 42 | 43 | # Use the full path to dotnet command as there's no symlink 44 | ENTRYPOINT ["/usr/share/dotnet/dotnet", "staticfiles.dll"] 45 | -------------------------------------------------------------------------------- /final-aspnet/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Dpb.StaticFiles 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /final-aspnet/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /final-aspnet/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace Dpb.StaticFiles 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | } 20 | 21 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseFileServer(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => {}); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /final-aspnet/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /final-aspnet/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /final-aspnet/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /final-aspnet/tmp.tar: -------------------------------------------------------------------------------- 1 | tmp/0001777000000000000000000000000013140662635010367 5ustar rootroot -------------------------------------------------------------------------------- /final-aspnet/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

FINAL!!!

9 | 10 | -------------------------------------------------------------------------------- /final-net6/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use dotnet runtime deps to gather all dependencies 2 | FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-alpine3.13-amd64 as base 3 | 4 | # Cleanup /lib 5 | RUN find /lib -type d -empty -delete && \ 6 | rm -r /lib/apk && \ 7 | rm -r /lib/sysctl.d 8 | 9 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env 10 | WORKDIR /app 11 | 12 | # Copy csproj and restore as distinct layers 13 | COPY *.csproj ./ 14 | RUN dotnet restore 15 | 16 | # Copy everything else and build 17 | COPY . . 18 | RUN dotnet publish \ 19 | --runtime alpine-x64 \ 20 | --self-contained true \ 21 | /p:PublishTrimmed=true \ 22 | /p:PublishSingleFile=true \ 23 | -c Release \ 24 | -o out 25 | 26 | # Create runtime image 27 | FROM scratch 28 | COPY --from=base /lib/ /lib 29 | COPY --from=base /usr/lib /usr/lib 30 | COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt 31 | 32 | # chmod hack: extract tmp.tar file with correct flags 33 | # see https://github.com/GoogleContainerTools/distroless/blob/main/base/tmp.tar 34 | ADD tmp.tar . 35 | 36 | ENV ASPNETCORE_URLS=http://+:8080 \ 37 | DOTNET_RUNNING_IN_CONTAINER=true \ 38 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true \ 39 | COMPlus_EnableDiagnostics=0 40 | 41 | WORKDIR /app 42 | COPY --from=build-env --chown=1111:1111 /app/out ./ 43 | USER 1111:1111 44 | EXPOSE 8080 45 | ENTRYPOINT ["./staticfiles"] 46 | -------------------------------------------------------------------------------- /final-net6/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | var app = builder.Build(); 6 | 7 | if (app.Environment.IsDevelopment()) 8 | { 9 | app.UseDeveloperExceptionPage(); 10 | } 11 | 12 | app.UseFileServer(); 13 | 14 | app.UseRouting(); 15 | 16 | app.Run(); 17 | -------------------------------------------------------------------------------- /final-net6/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /final-net6/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /final-net6/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /final-net6/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /final-net6/tmp.tar: -------------------------------------------------------------------------------- 1 | tmp/0001777000000000000000000000000013140662635010367 5ustar rootroot -------------------------------------------------------------------------------- /final-net6/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

FINAL!!!

9 | 10 | -------------------------------------------------------------------------------- /final/Dockerfile: -------------------------------------------------------------------------------- 1 | # Use dotnet runtime deps to gather all dependencies 2 | FROM mcr.microsoft.com/dotnet/runtime-deps:5.0.5-alpine3.13-amd64 as base 3 | 4 | # Cleanup /lib 5 | RUN find /lib -type d -empty -delete && \ 6 | rm -r /lib/apk && \ 7 | rm -r /lib/sysctl.d 8 | 9 | FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env 10 | WORKDIR /app 11 | 12 | # Copy csproj and restore as distinct layers 13 | COPY *.csproj ./ 14 | RUN dotnet restore 15 | 16 | # Copy everything else and build 17 | COPY . . 18 | RUN dotnet publish \ 19 | --runtime alpine-x64 \ 20 | --self-contained true \ 21 | /p:PublishTrimmed=true \ 22 | /p:PublishSingleFile=true \ 23 | -c Release \ 24 | -o out 25 | 26 | # Create runtime image 27 | FROM scratch 28 | COPY --from=base /lib/ /lib 29 | COPY --from=base /usr/lib /usr/lib 30 | COPY --from=base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt 31 | 32 | # chmod hack: extract tmp.tar file with correct flags 33 | # see https://github.com/GoogleContainerTools/distroless/blob/main/base/tmp.tar 34 | ADD tmp.tar . 35 | 36 | ENV ASPNETCORE_URLS=http://+:8080 \ 37 | DOTNET_RUNNING_IN_CONTAINER=true \ 38 | DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true \ 39 | COMPlus_EnableDiagnostics=0 40 | 41 | WORKDIR /app 42 | COPY --from=build-env --chown=1111:1111 /app/out ./ 43 | USER 1111:1111 44 | EXPOSE 8080 45 | ENTRYPOINT ["./staticfiles"] 46 | -------------------------------------------------------------------------------- /final/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Dpb.StaticFiles 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /final/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:37911", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "_2_debian": { 19 | "commandName": "Project", 20 | "dotnetRunMessages": "true", 21 | "launchBrowser": true, 22 | "applicationUrl": "http://localhost:5000", 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /final/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | namespace Dpb.StaticFiles 12 | { 13 | public class Startup 14 | { 15 | // This method gets called by the runtime. Use this method to add services to the container. 16 | // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | } 20 | 21 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseFileServer(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => {}); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /final/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /final/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /final/staticfiles.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /final/tmp.tar: -------------------------------------------------------------------------------- 1 | tmp/0001777000000000000000000000000013140662635010367 5ustar rootroot -------------------------------------------------------------------------------- /final/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World! 5 | 6 | 7 |

Hello World!

8 |

FINAL!!!

9 | 10 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "6.0.100" 4 | } 5 | } --------------------------------------------------------------------------------