-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to Windows container's env:PATH variable (Or any system wide env vars) #5234
Comments
This is actually a known issue, although we didn't produce a separate bug report for it yet. (And that's on me, I was supposed to do that a long time ago, the unresolved discussion is buried in comments on #3158) The problem is that BuildKit currently sets a default PATH in the image manifest environment block when one isn't set, which overrides what's set inside the image's registry. The workaround is to use the |
Thanks you! I don't know if you want me to leave the issue open until the PR is merged, or close it? As for a workaround, after your comment, I thought of a better? workaround, at least better for my usecase. So basically this FROM --platform=windows/amd64 mcr.microsoft.com/windows/servercore:ltsc2022
ARG SCRIPT
ARG SCRIPT_NAME
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-Command"]
Copy scripts .
RUN dir; .\install_git.ps1
RUN $env:PATH = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path; setx /M TMP_PATH $env:PATH
RUN echo "PATH: $env:PATH and TEMP path $env:TMP_PATH"
ENV PATH "$TMP_PATH"
RUN echo "AFTER_PATH: $env:PATH" Relevant output:
The .\install_git.ps1 for completness #Install git
Invoke-WebRequest -Uri "https://github.com/git-for-windows/git/releases/download/v2.45.2.windows.1/Git-2.45.2-64-bit.exe" -OutFile "git.exe"
$process = Start-Process -FilePath ".\git.exe" -ArgumentList "/VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS
/COMPONENTS=icons,ext\reg\shellhere,assoc,assoc_sh" -Wait -PassThru
Write-Host "Git install Error Code output: $($process.ExitCode)"
if ($process.ExitCode -ne 0) {
Write-Host "Error: Git installation failed. Exiting script."
Write-Host "Error code: $($process.ExitCode)"
exit 1
} Not how I am not the one setting the |
After a little bit of further tinkering FROM --platform=windows/amd64 mcr.microsoft.com/windows/servercore:ltsc2022
ARG SCRIPT
ARG SCRIPT_NAME
SHELL ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-Command"]
RUN $env:PATH = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path; setx /M TMP_PATH $env:PATH
ENV PATH "$TMP_PATH"
COPY scripts .
RUN ./check_path.ps1
RUN ./set_x.ps1
RUN ./check_path.ps1
RUN ./set_env_var.ps1
RUN ./check_path.ps1
RUN ./regedit.ps1
RUN ./check_path.ps1
RUN echo "AFTER_PATH: $env:PATH" Output
All the different ways seems to now actually set the environment variables, which makes it even a better workaround. No need to replicate any path changes. Just set it in the beginning to something, and then it seems to work as expected |
Environment
Running a Windows 2022 Core EC2 Instance with Containers enabled
(I am uncertain if this issues lies with buildx or buildkit, but gut feeling says buildkit)
Setup
To test setting path behaviour I use a few small powershell script to test
check_path.ps1
regedit.ps1
set_env_var.ps1
set_x.ps1
Finally the docker file
Behaviour
Buildx
When running this as ``docker buildx build . --progress=plain --no-cache`
The relevant output:
Normal docker build
With the command
docker build . --no-cache
Relevant output:
From what I can tell there are 2 things of concernt.
./check_path.ps1
step where the regedit key are the same, but the PATH env is different for the buildx build.(While I only really tested env:Path I suspect this goes for all system env vars)
I would expect the behavour to be the same, or at least a way to persistently set the environment variable so I can use it in further scripts.
Any help would be appreciated, and I am willing to test things if needed
The text was updated successfully, but these errors were encountered: