在Windows Docker容器中附加到PATH
我需要附加到Windows Docker容器中的PATH,我尝试了许多排列。
ENV PATH=%PATH%;C:\\Foo\\bin ENV PATH=$PATH;C:\\Foo\\bin ENV PATH="%PATH%;C:\Foo\bin" ENV PATH="$PATH;C:\Foo\bin" RUN "set PATH=%PATH%;C:\Foo\bin"
这些工作都不起作用:他们不评估先前存在的PATHvariables。
什么是正确的语法附加到PATH? 我可以附加到Docker内的PATH? (我可以在类似的Linux容器上)
您可以使用powershell脚本在容器中永久设置环境variables。
在docker上下文(例如setpath.ps1)中创build一个包含以下内容的powershell脚本:
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Foo\bin", [EnvironmentVariableTarget]::Machine)
将此脚本添加到您的容器dockerfile并运行该脚本。 把这样的东西添加到你的dockerfile中:
ADD ./setpath.ps1 c:/MyScripts/setpath.ps1 RUN powershell -Command c:\MyScripts\setpath.ps1