├── .dockerignore ├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── Controllers └── ValuesController.cs ├── Directory.Build.props ├── Dockerfile ├── Dotnet-Watch-Docker-Example.csproj ├── LICENSE ├── Program.cs ├── README.md ├── Startup.cs └── docker-compose.yml /.dockerignore: -------------------------------------------------------------------------------- 1 | bin\ 2 | obj\ 3 | .vscode\ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | obj -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to find out which attributes exist for C# debugging 3 | // Use hover for the description of the existing attributes 4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Attach Docker", 9 | "type": "coreclr", 10 | "request": "attach", 11 | "processId": "${command:pickRemoteProcess}", 12 | "sourceFileMap": { 13 | "/app": "${workspaceRoot}/" 14 | }, 15 | "pipeTransport": { 16 | "pipeCwd": "${workspaceRoot}", 17 | "pipeProgram": "docker", 18 | "pipeArgs": [ 19 | "exec", 20 | "-i", 21 | "dotnet_watch_docker_example" 22 | ], 23 | "quoteArgs": false, 24 | "debuggerPath": "/vsdbg/vsdbg" 25 | } 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/Dotnet-Watch-Docker-Example.csproj" 11 | ], 12 | "problemMatcher": "$msCompile" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace Dotnet_Watch_Docker_Example.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | [ApiController] 11 | public class ValuesController : ControllerBase 12 | { 13 | // GET api/values 14 | [HttpGet] 15 | public ActionResult> Get() 16 | { 17 | return new string[] { "value1", "value3" }; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(DefaultItemExcludes);$(MSBuildProjectDirectory)/obj/**/* 5 | $(DefaultItemExcludes);$(MSBuildProjectDirectory)/bin/**/* 6 | 7 | 8 | 9 | $(MSBuildProjectDirectory)/obj/container/ 10 | $(MSBuildProjectDirectory)/bin/container/ 11 | 12 | 13 | 14 | $(MSBuildProjectDirectory)/obj/local/ 15 | $(MSBuildProjectDirectory)/bin/local/ 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM microsoft/dotnet:sdk 2 | 3 | WORKDIR /vsdbg 4 | 5 | RUN apt-get update \ 6 | && apt-get install -y --no-install-recommends \ 7 | unzip \ 8 | && rm -rf /var/lib/apt/lists/* \ 9 | && curl -sSL https://aka.ms/getvsdbgsh \ 10 | | bash /dev/stdin -v latest -l /vsdbg 11 | 12 | ENV DOTNET_USE_POLLING_FILE_WATCHER 1 13 | 14 | WORKDIR /app 15 | 16 | ENTRYPOINT dotnet watch run --urls=http://+:5000 -------------------------------------------------------------------------------- /Dotnet-Watch-Docker-Example.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Aaron Housh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace Dotnet_Watch_Docker_Example 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dotnet-Watch-Docker-Example 2 | 3 | To run this example, just use 4 | ```console 5 | docker-compose up 6 | ``` 7 | 8 | navigate to: http://localhost:5000/api/values 9 | 10 | make any change to a file (such as Controllers > ValuesController, change a value), save, and refresh the browser, it will automatically rebuild. 11 | 12 | Want to debug a line? Add a breakpoint, hit F5, and choose the dotnet instance that is running your app from the dropdown. 13 | 14 | Tada! Debugging dotnet watch run inside a docker container :) 15 | -------------------------------------------------------------------------------- /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.HttpsPolicy; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.Extensions.DependencyInjection; 11 | using Microsoft.Extensions.Logging; 12 | using Microsoft.Extensions.Options; 13 | 14 | namespace Dotnet_Watch_Docker_Example 15 | { 16 | public class Startup 17 | { 18 | public Startup(IConfiguration configuration) 19 | { 20 | Configuration = configuration; 21 | } 22 | 23 | public IConfiguration Configuration { get; } 24 | 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); 28 | } 29 | 30 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 31 | { 32 | app.UseMvc(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.3' 2 | 3 | services: 4 | dotnet-watch-docker-example: 5 | container_name: dotnet_watch_docker_example 6 | image: dispersia/dotnet-watch-docker-example 7 | build: 8 | context: . 9 | ports: 10 | - 5000:5000 11 | volumes: 12 | - './:/app' --------------------------------------------------------------------------------