Search code examples
windowspowershelldockerhyper-v

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. I would like to set the system path to include the java path, but I can't figure out how. 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\""]

Solution

  • Looks like this Golang sample has a crufty way to do this: https://github.com/MicrosoftDocs/Virtualization-Documentation/blob/master/windows-container-samples/golang/Dockerfile#L24