Appending to PATH in a Windows Docker container

拈花ヽ惹草 提交于 2019-11-29 10:14:28

Unfortunately ENV won't work, because windows environment variable work a little differently than linux. more info

As of now the only way to do this is through RUN

But you don't need to create a separate file to do this. This can be done by the following much simpler one line command:

RUN setx path "%path%;C:\Foo\bin"

You can set environment variables permanently in the container using a powershell script.

Create a powershell script in yout docker context (e.g. setpath.ps1 ) containing this:

[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Foo\bin", [EnvironmentVariableTarget]::Machine)

Add this script to your container dockerfile and RUN the script. Add something like this to your dockerfile:

ADD ./setpath.ps1 c:/MyScripts/setpath.ps1
RUN powershell -Command c:\MyScripts\setpath.ps1
cherishty

[Environment]::SetEnvironmentVariable is a good way, but will not work in nanoserver. The best choice is:

RUN setx path '%path%;C:\Foo\bin'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!