2
votes

I'm trying to create a development Dockerfile for dotnet core 2. What I have so far is the following:

FROM microsoft/aspnetcore-build:2.0

VOLUME /app
WORKDIR /app
COPY . ./
ENV ASPNETCORE_SERVER.URLS http://*:5000
ENV ASPNETCORE_ENVIRONMENT Development
RUN dotnet restore
ENTRYPOINT dotnet watch run --configuration Debug

If I run:

dotnet restore
dotnet watch run

From the same folder everything seems to work just fine (the watcher starts). When I instead run that docker file (inside a docker-compose environment) it keeps shouting:

No executable found matching command "dotnet-watch"

My configuration file is the following:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
  </ItemGroup>
</Project>

and as you can see contains the infamous:

<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />

line that is usually what's causing the issue.

How can I make dotnet watch work on docker?

1

1 Answers

2
votes

I just had to dotnet restore in the ENTRYPOINT like this:

FROM microsoft/aspnetcore-build:2.0

VOLUME /app
WORKDIR /app
COPY . ./
ENV ASPNETCORE_SERVER.URLS http://*:5000
ENV ASPNETCORE_ENVIRONMENT Development
ENTRYPOINT dotnet restore && dotnet watch run --configuration Debug