File tree Expand file tree Collapse file tree 6 files changed +81
-40
lines changed Expand file tree Collapse file tree 6 files changed +81
-40
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,22 @@ This project is a boilerplate for building .NET API applications with various fe
6868
6969 ` ` `
7070
71+ 1.1 Setting cert
72+
73+ ```
74+ dotnet dev-certs https -ep ${HOME}/.aspnet/https/dotnetapi-boilerplate.pfx -p mypassword234
75+ dotnet dev-certs https --trust
76+
77+ ```
78+
79+ 1.2 Running the container with cert
80+
81+ ```
82+ docker pull mcr.microsoft.com/dotnet/samples: aspnetapp
83+ docker run --rm -it -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORTS=8001 -e ASPNETCORE_Kestrel__ Certificates__ Default__ Password="mypassword234" -e ASPNETCORE_Kestrel__ Certificates__ Default__ Path=/https/dotnetapi-boilerplate.pfx -v ${HOME}/.aspnet/https:/https/
84+
85+ ```
86+
71872. The application will be available at `http://localhost:7000` and `https://localhost:7001` (or the configured URL).
7288
7389### Health Check Endpoint
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ # Use the official .NET SDK image to build the application
2+ FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
3+ WORKDIR /app
4+
5+ # Expose the port the application runs on
6+ # EXPOSE 8080
7+ # EXPOSE 8000
8+ # ENV ASPNETCORE_URLS=https://+;http://+
9+ # ENV ASPNETCORE_HTTPS_PORTS=8001
10+ # ENV ASPNETCORE_HTTP_PORTS=8000
11+
12+ ARG BUILD_CONFIGURATION=Release
13+
14+ # Copy the project files and restore dependencies
15+ COPY . ./
16+ RUN dotnet restore
17+
18+ # Build the application
19+ RUN dotnet publish -c Release -o out
20+
21+ # Use the official .NET runtime image to run the application
22+ FROM mcr.microsoft.com/dotnet/aspnet:9.0
23+ WORKDIR /app
24+ COPY --from=build /app/out .
25+
26+
27+ # Run the application
28+ ENTRYPOINT ["dotnet" , "NetAPI.dll" ]
Original file line number Diff line number Diff line change 77using Microsoft . Extensions . Configuration ;
88
99
10- var builder = WebApplication
11- . CreateBuilder ( args )
12- . ConfigureApplicationBuilder ( ) ;
13-
14- var IsDevelopment = builder . Environment . IsDevelopment ( ) ;
15-
16- var configuration = builder . Configuration ;
17-
18- var app = builder
19- . Build ( )
20- . ConfigureApplication ( ) ;
21-
2210try
2311{
12+ var builder = WebApplication . CreateBuilder ( args ) . ConfigureApplicationBuilder ( ) ;
13+
14+ var app = builder . Build ( ) ;
15+
16+ app . ConfigureApplication ( ) ;
2417
25- // Console.WriteLine(app.Environment.IsDevelopment().ToString());
26- Log . Information ( $ "Starting host in { builder . Environment . EnvironmentName } mode") ;
27- // Console.WriteLine($"Running in Dev={isDev} mode");
18+ // Log.Information($"Application is running in {builder.Environment.EnvironmentName} mode.");
2819
2920 app . Run ( ) ;
21+
3022 return 0 ;
3123}
3224catch ( Exception ex )
Original file line number Diff line number Diff line change 1818 "environmentVariables" : {
1919 "ASPNETCORE_ENVIRONMENT" : " Development"
2020 }
21+ },
22+ "Docker" : {
23+ "commandName" : " Docker" ,
24+ "launchBrowser" : true ,
25+ "launchUrl" : " {Scheme}://{ServiceHost}:{ServicePort}/swagger" ,
26+ "environmentVariables" : {
27+ "ASPNETCORE_HTTPS_PORTS" : " 8081" ,
28+ "ASPNETCORE_HTTP_PORTS" : " 8080"
29+ },
30+ "publishAllPorts" : true ,
31+ "useSSL" : true
2132 }
2233 }
23- }
34+ }
Original file line number Diff line number Diff line change 1+ version : ' 3.4'
2+
3+ services :
4+ dotnetapi-boilerplate :
5+ image : dotnetapi-boilerplate
6+ build :
7+ context : .
8+ dockerfile : Dockerfile
9+ ports :
10+ - " 8080:8080"
11+ - " 8081:8081"
12+ environment :
13+ - ASPNETCORE_ENVIRONMENT=Production
14+ - ASPNETCORE_URLS=https://+:8081;http://+:8080
15+ - ASPNETCORE_Kestrel__Certificates__Default__Password=mypassword234
16+ - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/dotnetapi-boilerplate.pfx
17+ volumes :
18+ - ~/.aspnet/https:/https:ro
You can’t perform that action at this time.
0 commit comments