├── .gitignore ├── Readme.md ├── banner.png ├── docker-compose.yml ├── dotnetcore-app ├── Dockerfile └── src │ ├── Program.cs │ └── dotnetcore-app.csproj └── nginx ├── Dockerfile └── nginx.conf /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.*~ 3 | project.lock.json 4 | .DS_Store 5 | *.pyc 6 | 7 | # Visual Studio Code 8 | .vscode 9 | 10 | # User-specific files 11 | *.suo 12 | *.user 13 | *.userosscache 14 | *.sln.docstates 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | build/ 24 | bld/ 25 | [Bb]in/ 26 | [Oo]bj/ 27 | msbuild.log 28 | msbuild.err 29 | msbuild.wrn 30 | 31 | # Visual Studio 2015 32 | .vs/ -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Run ASP.NET Core Application with Nginx on Docker Compose 2 | *** 3 | ![logo](https://raw.githubusercontent.com/selcukusta/docker-compose-netcore-app/master/banner.png) 4 | *** 5 | Expose and mappings port can be changed on: 6 | - dotnetcore-app/Dockerfile 7 | - nginx/nginx.conf 8 | - docker-compose.yml 9 | -------------------------------------------------------------------------------- /banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/selcukusta/docker-compose-netcore-app/923622a0438302fc3bd455a1bc2c831068dfd6ca/banner.png -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.3' 2 | 3 | services: 4 | sample-site: 5 | build: 6 | context: ./dotnetcore-app 7 | dockerfile: Dockerfile 8 | expose: 9 | - "5000" 10 | ports: 11 | - "5000:5000" 12 | 13 | proxy: 14 | build: 15 | context: ./nginx 16 | dockerfile: Dockerfile 17 | ports: 18 | - "8080:8080" 19 | links: 20 | - sample-site 21 | depends_on: 22 | - sample-site -------------------------------------------------------------------------------- /dotnetcore-app/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:latest 2 | COPY src /app 3 | WORKDIR /app 4 | RUN ["dotnet", "restore"] 5 | RUN ["dotnet", "build", "--configuration", "Debug"] 6 | EXPOSE 5000/tcp 7 | ENV ASPNETCORE_URLS https://*:5000 8 | ENTRYPOINT ["dotnet", "run", "--server.urls", "http://*:5000"] -------------------------------------------------------------------------------- /dotnetcore-app/src/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.Extensions.Logging; 5 | using System.Text; 6 | using System.Linq; 7 | 8 | namespace DotNetCoreApp 9 | { 10 | public class Startup 11 | { 12 | public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) 13 | { 14 | loggerFactory.AddConsole(LogLevel.Error); 15 | app.Run(context => 16 | { 17 | var cookies = context.Request.Cookies; 18 | var cookieDefinitionBuilder = new StringBuilder(); 19 | cookies.ToList().ForEach(cookie => 20 | { 21 | cookieDefinitionBuilder.AppendLine($"{cookie.Key}={cookie.Value}"); 22 | }); 23 | return context.Response.WriteAsync(cookieDefinitionBuilder.ToString()); 24 | }); 25 | } 26 | } 27 | 28 | public class Program 29 | { 30 | public static void Main(string[] args) 31 | { 32 | var host = new WebHostBuilder() 33 | .ConfigureLogging((factory) => 34 | { 35 | factory.AddConsole(LogLevel.Error); 36 | }) 37 | .UseKestrel() 38 | .UseStartup() 39 | .Build(); 40 | 41 | host.Run(); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /dotnetcore-app/src/dotnetcore-app.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /nginx/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx 2 | COPY nginx.conf /etc/nginx/conf.d/sample-site.conf -------------------------------------------------------------------------------- /nginx/nginx.conf: -------------------------------------------------------------------------------- 1 | server { 2 | set $new_cookie $http_cookie; 3 | 4 | if ($http_cookie ~ "(.*)(?:^|;)\s*non_ascii=[^;]+(.*)") { 5 | set $new_cookie $1$2; 6 | } 7 | proxy_set_header Cookie $new_cookie; 8 | 9 | listen 8080; 10 | server_name localhost; 11 | 12 | location /abc/ { 13 | proxy_pass http://sample-site:5000/; 14 | proxy_http_version 1.1; 15 | } 16 | } 17 | --------------------------------------------------------------------------------