DockerFile:将ARG传递到dotnet构建以进行构建配置

时间:2019-04-16 15:12:53

标签: docker dockerfile

我无法在DockerFile中使用Docker ARG,特别是在构建.net Core项目时:

FROM microsoft/dotnet:2.2-sdk-nanoserver-1809 AS build
ARG target_configuration=Debug
WORKDIR /src
COPY MyProject/MyProject.csproj MyProject/
RUN dotnet restore MyProject/MyProject.csproj
COPY . .
WORKDIR /src/MyProject
RUN dotnet build --configuration $target_configuration --no-restore -o /app MyProject.csproj

'$ target_configuration'不会被替换。我尝试过$ {xx},“ $ xx”,“ $ {xx}”等的各种组合,但是我没有赢。 FWIW,在这种情况下,我收到的消息是:

  

警告MSB3052:编译器的参数无效,   '/ define:$ TARGET_CONFIGURATION'

我知道在容器运行时ARG不可用的局限性(以及对ENV变量的相关需求),并且在FROM语句之前定义时在构建期间ARG不可用,但是这些是(我认为)在这里不适用。

我在做什么错了?

Docker环境:

Server: Docker Engine - Community
Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.24)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:28:48 2019
  OS/Arch:          windows/amd64
  Experimental:     false

编辑:

(TL; DR)对Windows映像使用%var%

Docker RUN在指定的容器中运行,这意味着运行该命令的外壳会影响变量替换的完成方式。因此,对于Windows容器,请使用%var%

Docker论坛中的

This线程还有更多

1 个答案:

答案 0 :(得分:2)

它可能正在作为exe运行,因此请尝试将其用作exe环境

RUN dotnet build --configuration %target_configuration% ...
相关问题