Sitecore 10 Docker: install packages in CM environment

While testing functionality in my Sitecore Docker XP1 environment locally, I wanted to install a package to get some Sitecore items and files in my environment. In this case, it was for some custom fields and their views.

This isn't the best way to include them, ideally you have your items synchronized and your files just deployed. But, I had the package and wanted to do this.
And since I'll have my items in Sitecore after the installation, it will be easier to use item synchronization to get them back to disk and my repository.

Problem: by default the IIS_IUSRS that installs the pacakge doesn't have appropriate access rights to actually deploy files in non-standard folders.
Eg. a new folder in the root of wwwroot. It should have access to the bin and sitecore folder, but creating new folders isn't allowed.

This was my error:

The log file showed the real problem: couldn't delete a file - even though it didn't exist at that point - due to access rights. The CustomFields folder doesn't exist and couldn't be checked by the IIS_ISUSRS.

    ManagedPoolThread #1 09:35:39 ERROR Installation failed:
    System.Exception: Background process failed: Failed to delete the file
    C:\inetpub\wwwroot\CustomFields\Dialogs\SingleSelectView.aspx' --->
    
    System.Exception: Failed to delete the file
    'C:\inetpub\wwwroot\CustomFields\Dialogs\SingleSelectView.aspx' --->
    
    System.IO.DirectoryNotFoundException: Could not find a part of the path
    'C:\inetpub\wwwroot\CustomFields\Dialogs\SingleSelectView.aspx'.

Solution: Give the IIS_IUSRS the appropriate rights!
This can be done in the build Dockerfile of the CM.
Just add RUN icacls 'C:\inetpub\wwwroot' /grant 'IIS_IUSRS:(F)' /t
Which will give the user full access on the wwwroot folder.

Special thanks go to J.F. Larente of Sitecore for providing the solution.

References: