I am trying to add the X-Forwarded-For request header to the mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019 Docker base image using Add-WebConfigurationProperty.
My Dockerfile looks like:
FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
ARG source
RUN Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='Default Web Site']/logFile/customFields" -name "." -value "@{logFieldName='X-Forwarded-For';sourceName='X-FORWARDED-FOR';sourceType='RequestHeader'}"
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
When I run docker build I get the following error
Sending build context to Docker daemon 4.096kB
Step 1/5 : FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
---> 30379ad7580b
Step 2/5 : ARG source
---> Using cache
---> 90c760c37d26
Step 3/5 : RUN Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='Default Web Site']/logFile/customFields" -name "." -value @{logFieldName='X-Forwarded-For';sourceName='X-FORWARDED-FOR';sourceType='RequestHeader'}
---> Running in 4210cd6ae606
Add-WebConfigurationProperty : Expected an operator name (eg. 'and')
Input: get-config("MACHINE/WEBROOT/APPHOST")/system.applicationHost/sites/site[
@name=Default Web Site]/logFile/customFields
Position: 86
Length: 3
Fragment: Web
At line:1 char:76
+ ... yContinue'; Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-WebConfigurationProperty]
, ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.IIs.PowerShel
l.Provider.AddConfigurationPropertyCommand
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='Default Web Site']/logFile/customFields" -name "." -value @{logFieldName='X-Forwarded-For';sourceName='X-FORWARDED-FOR';sourceType='RequestHeader'}' returned a non-zero code: 1
The Dockerfile builds fine without the RUN Add-WebConfigurationProperty. If I build it without the RUN Add-WebConfigurationProperty I can run the container and execute the the Add-WebConfigurationProperty command and see that it does add the field to the log file. Any idea why it won't work via the Dockerfile.
I've run into some escaping issues with Windows Dockerfiles as well, sometimes I pull in a powershell script for things I need.
In this case since I assume you just want the field added, you can use:
Hope this helps!
Thanks!