gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:19:59 25 4
gpt4 key购买 nike

我无法在我的 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,我在这种情况下得到的信息是:

warning MSB3052: The parameter to the compiler is invalid, '/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%

This Docker-Forum 中的线程有更多内容

最佳答案

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

RUN dotnet build --configuration %target_configuration% ...

关于DockerFile:将 ARG 传递给 dotnet build 以进行构建配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55711434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com