0

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.

5
  • you can use a cntlm service to hide your username and password and use that for your docker configuration. Commented Jan 16, 2018 at 13:36
  • @Edwin thanks, that can solve the imminent issue but i would like to know if/how it is possible to create some sort of environment from powershell scripts for within the Docker build context. I assume, each RUN starts a new shell or something like this. Commented Jan 16, 2018 at 13:45
  • I don't get what do you want to achive with this question, because you have asked how to save the variables in your environment in your other question Commented Jan 16, 2018 at 13:56
  • @Edwin if i could assign variables in a powershell script so they are available to subsequent RUN calls it would help me with this particular problem. But in general i want to be able to modify the shell (e.g. set a global proxy) with a powershell script Commented Jan 16, 2018 at 14:33
  • again this is what you've asked in the other question and the answer is what you already thought: using "ENV or ARG" depending how you want to init your global variables. Commented Jan 16, 2018 at 15:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.