In order to build my windows docker image, i need to fetch some data from the internet. Unfortunately, there is a proxy in between so i need to configure the build shell environment accordingly.
In order to not display the username and password during every build (which can be seen in the log on e.g. Jenkins) i am trying to execute a powershell script within the following Dockerfile
FROM microsoft/windowsservercore
SHELL ["powershell", "-Command"]
# set proxy credentials
COPY set_proxy.ps1 C:/Temp/
RUN """ C:/Temp/set_proxy.ps1"""
# download setups from web
RUN Invoke-WebRequest ...
and the set_proxy.ps1
file is the following (based on this and this)
$username = 'proxyUser'
$password = 'proxyPassword'
(New-Object System.Net.WebClient).Proxy.Credentials = New-Object System.Net.NetworkCredential($username, $password)
[Environment]::SetEnvironmentVariable("""HTTP_PROXY""", """http://$($username):$($password)@proxyHost:proxyPort""", [EnvironmentVariableTarget]::Machine)
[Environment]::SetEnvironmentVariable("""HTTPS_PROXY""", """http://$($username):$($password)@proxyHost:proxyPort""", [EnvironmentVariableTarget]::Machine)
When i execute the Invoke-WebRequest
within the set_proxy.ps1
script the download works, if i use the extra RUN
step, it doesnt work, i get an error message from the proxy.
This might be related to how Docker on Windows handles variables.