简体   繁体   English

如何在我的 dockerfile 中为 Windows 容器设置系统路径?

[英]How do I set System Path in my dockerfile for a Windows Container?

I am writing a Dockerfile to create a container for OpenJDK using the new, native docker support in Windows 10. This is NOT using docker-toolbox.我正在编写一个 Dockerfile 来使用 Windows 10 中新的原生 docker 支持为 OpenJDK 创建一个容器。这不是使用 docker-toolbox。 I would like to set the system path to include the java path, but I can't figure out how.我想设置系统路径以包含 java 路径,但我不知道如何。 I've tried several variations of the following file, but I can't get the path to set correctly.我尝试了以下文件的几种变体,但无法正确设置路径。

FROM nanoserver:latest

RUN powershell -Command "Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force;Set-PSRepository -Name PSGallery -InstallationPolicy Trusted;Install-Module PS7Zip;" 

ADD https://github.com/ojdkbuild/ojdkbuild/releases/download/1.8.0.91-3/java-1.8.0-openjdk-1.8.0.91-3.b14.windows.x86_64.zip java.zip

RUN setx /M JRE_HOME C:\java-1.8.0-openjdk-1.8.0.91-3.b14.windows.x86_64\jre
RUN setx /M JAVA_HOME C:\java-1.8.0-openjdk-1.8.0.91-3.b14.windows.x86_64
RUN powershell -Command "Expand-7Zip java.zip"
RUN ["powershell", "$env:Path=$env:Path+\";C:\\java-1.8.0-openjdk-1.8.0.91-3.b14.windows.x86_64\\bin\""]

看起来这个 Golang 示例有一个粗暴的方法来做到这一点: https : //github.com/MicrosoftDocs/Virtualization-Documentation/blob/master/windows-container-samples/golang/Dockerfile#L24

Unfortunately, Powershell does not allow modifying the system path variable using that method.不幸的是,Powershell 不允许使用该方法修改系统路径变量。 The $env:Path gives read access to the system path, not write. $env:Path提供对系统路径的读访问,而不是写。 Which means if you change $env:Path it will only affect your current PS environment.这意味着如果您更改$env:Path它只会影响您当前的 PS 环境。

See this link for a way to make changes to the system path variable: http://codingbee.net/tutorials/powershell/powershell-make-a-permanent-change-to-the-path-environment-variable/有关更改系统路径变量的方法,请参阅此链接: http : //codingbee.net/tutorials/powershell/powershell-make-a-permanent-change-to-the-path-environment-variable/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM