Windows Docker添加自定义标头

问题描述 投票:0回答:1

我正在尝试使用X-Forwarded-Formcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019请求标头添加到Add-WebConfigurationProperty Docker基础映像中。

我的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

没有RUN Add-WebConfigurationProperty,Dockerfile的构建良好。如果在不使用RUN Add-WebConfigurationProperty的情况下进行构建,则可以运行该容器并执行Add-WebConfigurationProperty命令,然后查看它确实将字段添加到日志文件中。知道为什么它不能通过Dockerfile起作用。

windows docker dockerfile windows-container windows-server-container
1个回答
0
投票

我也遇到了Windows Dockerfile的一些转义问题,有时我会根据需要添加一个Powershell脚本。

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

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

希望这会有所帮助!

谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.