我正在尝试使用将X-Forwarded-For
请求标头添加到mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
Docker 基础映像中Add-WebConfigurationProperty
。
我的 Dockerfile 看起来像:
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} .
当我运行 docker build 时,出现以下错误
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
Dockerfile 在没有RUN Add-WebConfigurationProperty
. 如果我在没有它的情况下构建它,RUN Add-WebConfigurationProperty
我可以运行容器并执行Add-WebConfigurationProperty
命令并看到它确实将字段添加到日志文件中。知道为什么它不能通过 Dockerfile 工作。