0

我正在尝试使用将X-Forwarded-For请求标头添加到mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019Docker 基础映像中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 工作。

4

1 回答 1

0

我也遇到了 Windows Dockerfiles 的一些转义问题,有时我会为我需要的东西拉入一个 powershell 脚本。

在这种情况下,因为我假设您只想添加该字段,您可以使用:

-filter "system.applicationHost/sites/siteDefaults/logFile/customFields"

希望这可以帮助!

谢谢!

于 2020-01-28T01:07:36.110 回答