In a dockerfile, how to delete a directory and its contents from docker image? (windows)

I’m using the python:3.6.5-windowsservercore base image.

COPY . /app copies the build context into C:app. This includes certain secret keys required for building the project.

After running the build, I want to delete keys folder (C:appkeys), for this I use:

RUN powershell.exe Remove-Item -Path "C:appkeys" -Force

This gives me following error:

Step 10/14 : RUN powershell.exe Remove-Item -Path C:appkeys -Force
 ---> Running in 4e22124332b1
Remove-Item : Object reference not set to an instance of an object.
At line:1 char:1
+ Remove-Item -Path C:appkeys -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Remove-Item], NullReferenceEx
   ception
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShe
   ll.Commands.RemoveItemCommand

The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; powershell.exe Remove-Item -Path C:appkeys -Force' returned a non-zero code: 1

What is the way to delete directory inside the image?

Source: StackOverflow