Dockerfile附加PATH环境变量不起作用?

时间:2019-03-21 15:56:24

标签: docker dockerfile

我认为这很简单,并且确实可以找到很多答案,但不确定为什么它对我不起作用。

首先,没有设置任何ENV PATH =,我可以检查PATH的默认值是

  

C:\ Windows \ system32; C:\ Windows; C:\ Windows \ System32 \ Wbem; C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \; C:\ Users \ ContainerAdministrator \ AppData \ Local \ Microsoft \ WindowsApps

我仅通过运行图像并使用CMD echo %PATH%进行检查。

但是,使用以下设置,所有默认值都消失了,不去理会新值(看起来真的像它无法获得默认值或只是该值是空的):

ENV PATH = "C:\Program Files\dotnet\:${PATH}"

以下是各种尝试(无效):

#this even tries removing spaces around the = 
#like some ones warned that could break the PATH
ENV PATH="C:\Program Files\dotnet:${PATH}"
ENV PATH = "C:\Program Files\dotnet\:$PATH"
ENV PATH = "C:\Program Files\dotnet:${PATH}"
ENV PATH = "C:\Program Files\dotnet:$PATH"   
ENV PATH = "C:\Program Files\dotnet;${PATH}"
ENV PATH = "C:\Program Files\dotnet;$PATH"
ENV PATH = "C:\Program Files\dotnet;$env:PATH"

使用上述设置之一,PATH(在正在运行的容器上执行cmd时由echo %PATH%检查)变成C:\Program Files\dotnet(在某些情况下可能还会附加一些字符)。

真的,我想为这样一个简单的问题把头撞在墙上,但花了我几个小时。真的吗?

这是完整的dockerfile:

# escape=`

FROM microsoft/dotnet:2.1-sdk-nanoserver-1803 AS dotnet

FROM microsoft/dotnet-framework:4.7.2-runtime-windowsservercore-1803

ENV DOTNET_PATH="C:\Program Files\dotnet" 
COPY --from=dotnet ${DOTNET_PATH} ${DOTNET_PATH}

ENV PATH = "C:\Program Files\dotnet\:${PATH}"

ENV ASPNETCORE_URLS=http://+:80 `

DOTNET_RUNNING_IN_CONTAINERS=true `

DOTNET_SKIP_FIRST_TIME_EXPERIENCE="true"

我希望这里有人指出问题所在。谢谢!

1 个答案:

答案 0 :(得分:1)

RUN setx /M PATH "C:\Program Files\dotnet;%PATH%"