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

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

我无法在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在指定的容器中运行,这意味着运行该命令的shell会影响变量的替换方式。因此,对于Windows容器,请使用%var%

Docker-Forum中的This线程还有一点

docker dockerfile
1个回答
2
投票

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

RUN dotnet build --configuration %target_configuration% ...
© www.soinside.com 2019 - 2024. All rights reserved.