microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
175 stars 26 forks source link

Framework target thinks build_context == wwwroot #383

Closed davhdavh closed 3 months ago

davhdavh commented 1 year ago

Framework and core targets does not interpret the build context in the same way

Microsoft.Docker.Templates.windows.dotnetframework.aspnet.docker-compose.vs.debug.yml has

volumes:
- $build_context$:C:\inetpub\wwwroot

Microsoft.Docker.Templates.windows.dotnetcore.aspnetcore.docker-compose.vs.debug.yml has

volumes:
  - $app_folder_path$:C:\app
  - $full_build_context$:C:\src

This is a huge problem, because framework targets are unable to include any dockerfile commands that target files outside of the primary source directory, e.g. COPY [ "myutil\myutil.exe", "c:\" ].

The proper generated file for framework should be

volumes:
  - $app_folder_path$:C:\inetpub\wwwroot
  - $full_build_context$:C:\src
davhdavh commented 1 year ago

workaround is quite complex...

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8 AS base
WORKDIR /
SHELL ["powershell"]
#move website to c:\app due to visual studio docker https://github.com/microsoft/DockerTools/issues/383
RUN Import-Module WebAdministration; `
    mkdir c:\app; `
    Set-ItemProperty 'IIS:\Sites\Default Web Site' -Name 'physicalPath' -Value 'c:\app';

and in docker-compose.yml add

    volumes:
    - .\myactualwebfolder:C:\app
NCarlsonMSFT commented 1 year ago

@davhdavh FYI the build context being different is intentional. ASP.NET Core uses the solution as the build context to support building in the container with projects references. The ASP.NET scaffolding published on the host, so it uses the smaller build context of the project folder.

If you need a file from outside your project directory in an ASP.NET project, you can change the build context: Change the property "context" under your service's build property in docker-compose.yml. When you change it, you need to make sure you update the relative path to your dockerfile, and the relative paths in your Dockerfile. You should also move your .dockerignore file to the new build context and update its relative paths to the new location.

Specific to supporting VS you also need to add a file docker-compose.vs.debug.yml and override the arg source and the volume for C:\inetpub\wwwroot to handle the moved context. Here is an example for my project WebApplication8 having a build context of the solution directory:

services:
  webapplication8:
    build:
      args:
        source: WebApplication8/obj/Docker/empty/
    volumes:
      - .\WebApplication8:C:\inetpub\wwwroot
davhdavh commented 1 year ago

My point was consistency... The core docker is vastly different from the framework one. Your workaround doesn't work, since 'C:\inetpub\wwwroot' should be the 'framework project', and build context needs to be the 'solution'.

dbreshears commented 3 months ago

We are unfortunately unable to prioritize this. Closing.