Appending to PATH in a Windows Docker container

前端 未结 4 1259
别跟我提以往
别跟我提以往 2020-12-16 13:22

I need to append to the PATH within a Windows Docker container, and I\'ve tried many permutations.

ENV PATH=%PATH%;C:\\\\Foo\\\\bin
ENV PATH=$PATH;C:\\\\Foo\         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 13:52

    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
    

提交回复
热议问题