Tools, FAQ, Tutorials:
Use "ENV" Instruction on Windows Image
How to use "ENV" Instruction in Dockerfile for Windows images?
✍: FYIcenter.com
In a Linux environment, the "ENV" instruction does two things in the image build process:
However, the "ENV" instruction seems not able to provide local variables. But it does inserting an environment variable to the Windows image.
1. Enter the following Dockerfile, JavaImage, to try the "ENV" instruction:
C:\fyicenter> type JavaImage FROM openjdk ENV CLASSPATH="C:\\FYI Center" RUN ["PowerShell", "Get-ChildItem", "Env:CLASSPATH"] # RUN ["PowerShell", "mkdir", $CLASSPATH] RUN ["PowerShell", "mkdir", "\"C:\\FYI Center\""] COPY ["Hello.java", "C:/FYI Center/Hello.java"] RUN ["javac", "C:\\FYI Center\\Hello.java"] ENTRYPOINT ["java", "Hello"]
2. Build the image and run it:
C:\fyicenter> docker build --file JavaImage --tag myjava . Sending build context to Docker daemon 12.87MB Step 1/7 : FROM openjdk Step 2/7 : ENV CLASSPATH="C:\\FYI Center" Step 3/7 : RUN ["PowerShell", "Get-ChildItem", "Env:CLASSPATH"] Name Value ---- ----- CLASSPATH C:\FYI Center Step 4/7 : RUN ["PowerShell", "mkdir", "\"C:\\FYI Center\""] Mode Length Name ---- ------ ---- d----- FYI Center Step 5/7 : COPY ["Hello.java", "C:/FYI Center/Hello.java"] Step 6/7 : RUN ["javac", "C:\\FYI Center\\Hello.java"] Step 7/7 : ENTRYPOINT ["java", "Hello"] Successfully built 110a378f5d8a Successfully tagged myjava:latest C:\fyicenter> docker run --name myjava myjava Hello world! C:\fyicenter> docker rm myjava C:\fyicenter> docker image rm myjava
Ok, we are able to use "ENV" instruction to insert an environment variable to the Windows image.
⇒ Docker Container Platform - Tutorials
⇐ "shell" Format vs. "exec" Format
2021-11-30, 633🔥, 0💬
Popular Posts:
How to use "link" command tool to link objet files? If you have object files previously compiled by ...
How To Protect Special Characters in Query String in PHP? If you want to include special characters ...
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...
How to create Hello-3.1.epub with WinRAR? I have all required files to create Hello-3.1.epub. To cre...
How to use the "rewrite-uri" Policy Statement for an Azure API service operation? The "rewrite-uri" ...