0

While debugging in Visual Studio I receive the following error:

Access is denied

This previously worked but something recently changed to break this. Perhaps related to a change made in Docker Desktop for Windows 4.7.1.

1 Answer 1

1

Let's say you start with a default console app with Docker support. It would seem that the access required in the container to run the remote debugger has changed.

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["ConsoleApp1/ConsoleApp1.csproj", "ConsoleApp1/"]
RUN dotnet restore "ConsoleApp1/ConsoleApp1.csproj"
COPY . .
WORKDIR "/src/ConsoleApp1"
RUN dotnet build "ConsoleApp1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ConsoleApp1.csproj" -c Release -o /app/publish

FROM base AS final
USER ContainerUser
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ConsoleApp1.dll"]

Update the base stage to the following:

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
USER ContainerAdministrator
WORKDIR /app

Doing this allows Visual Studio to connect to the remote debugger and run elevated. Be sure to downgrade to ContainerUser on the final stage.

Container Security

Microsoft shares some details about container security in the article here.

We strongly recommended that when deploying a Windows server container to any multi-tenant environment that your application runs via the ContainerUser account.

The images you build for distribution should be configured with ContainerUser to minimize risk to your environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.