Win10 Docker Build : Invoke-WebRequest : Unable to connect to the remote server - windows

I am going to create a docker image of angular web application to other windows machine. When it comes to the command execution :
docker build -t node .
It gives the following exception:
Invoke-WebRequest : Unable to connect to the remote server
At line:1 char:73
+ ... yContinue'; Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt
pWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
ll.Commands.InvokeWebRequestCommand
The command 'powershell -Command $ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue'; Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v8.11.0/node-v8.11.0-win-x64.zip"; Expand-Archive nodejs.zip -DestinationPath C:\; Rename-Item "C:\\node-v8.11.0-win-x64" c:\nodejs' returned a non-zero code: 1
Would you please tell me how to correct the line 10 so that the zip file can be extracted ?
Here is my Dockerfile
FROM mcr.microsoft.com/windows/servercore:1803 as installer
ENV NPM_CONFIG_LOGLEVEL info
ENV NODE_VERSION 8.11.0
ENV NODE_SHA256 7b2409605c871a40d60c187bd24f6f6ddf10590df060b7d905ef46b3b3aa7f81
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]
RUN Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v8.11.0/node-v8.11.0-win-x64.zip"; Expand-Archive nodejs.zip -DestinationPath C:\; Rename-Item "C:\\node-v8.11.0-win-x64" c:\nodejs
FROM mcr.microsoft.com/windows/nanoserver:1803
WORKDIR C:\nodejs
COPY --from=installer C:\nodejs\ .
RUN SETX PATH C:\nodejs
RUN npm config set registry https://registry.npmjs.org/
WORKDIR /app
# install and cache app dependencies
COPY src/WebSpa/package.json /app/src/WebSpa/package.json
WORKDIR /app/src/WebSpa
RUN npm install
RUN npm install -g #angular/cli#latest
# add app
COPY . /app
# start app
CMD cd /app/src/WebSpa && ng serve --host 0.0.0.0

Not sure if this would help but I was having a similar issue using Invoke-WebRequest : Unable to connect to the remote server and solved it by passing proxy server address as a parameter. Try:
Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v8.11.0/node-v8.11.0-win-x64.zip" -Proxy http://yourproxyserver.com:port;

Related

Can't install DataDog MSI in Dockerfile

From everything I have read, I should be able to do this:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ADD https://ddagent-windows-stable.s3.amazonaws.com/datadog-agent-7-latest.amd64.msi C:\datadog-agent-7-latest.amd64.msi
RUN Start-Process msiexec.exe -Wait -ArgumentList '/qn /i C:\datadog-agent-7-latest.amd64.msi APIKEY=abc123 /L*V C:\install.log'
It looks like it built correctly:
> docker build -t test .
Sending build context to Docker daemon 4.608kB
Step 1/4 : FROM mcr.microsoft.com/windows/servercore:ltsc2019
---> 71d3f266f3af
Step 2/4 : SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
---> Running in 1d931a586756
Removing intermediate container 1d931a586756
---> 277770d39d39
Step 3/4 : ADD https://ddagent-windows-stable.s3.amazonaws.com/datadog-agent-7-latest.amd64.msi C:/datadog-agent-7-latest.amd64.msi
Downloading [==================================================>] 146.9MB/146.9MB
---> 93223b61dad3
Step 4/4 : RUN Start-Process msiexec.exe -Wait -ArgumentList '/qn /i C:\datadog-agent-7-latest.amd64.msi APIKEY="abc123" /L*V C:\install.log'
---> Running in 619d7bb20f3b
Removing intermediate container 619d7bb20f3b
---> ddc461e4525a
Successfully built ddc461e4525a
Successfully tagged test:latest
But when I check in the container to see if it installed in C:\Program Files\Datadog, I am not seeing any of the files I am expecting from the installation.
I added the flag to give the install some extra logs (/L*V C:\install.log) but didn't see much in there. I have confirmed the msiexec command works on a Windows host, just not in the Docker build from what I can tell. Is there something simple that I'm missing?

How to update path in Windows container for Docker?

I am trying to update the path inside my container. I have been everywhere and checked out several threads on this and nothing works. So, that's the trick?
# escape=`
ARG SDK_VERSION=4.8
FROM mcr.microsoft.com/dotnet/framework/sdk:${SDK_VERSION}
ENV NODE_VERSION=8.11.2
HEALTHCHECK NONE
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object
System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;C:/Foo/bin"
USER ContainerUser
SHELL ["cmd", "/S", "/C"]
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
This is the error:
PS C:\users\cbongiorno\source> docker build -t mercury:latest -m 4GB -f Dockerfile i18n-tools
Sending build context to Docker daemon 2.057MB
Step 1/10 : ARG SDK_VERSION=4.8
Step 2/10 : FROM mcr.microsoft.com/dotnet/framework/sdk:${SDK_VERSION}
---> 4a9d58026a2d
Step 7/10 : RUN setx /M PATH "%PATH%;C:/Foo/bin"
---> Running in 1caf9e758af2
SUCCESS: Specified value was saved.
C:/Foo/bin : The term 'C:/Foo/bin' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:96
+ ... ogressPreference = 'SilentlyContinue'; setx /M PATH %PATH%;C:/Foo/bin
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:/Foo/bin:String) [], ParentCo
ntainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; setx /M PATH "%PATH%;C:/Foo/bin"' returned a non-zero code: 1
There are at least two ways to update the PATH:
Using setx as the earlier answer suggests and as is displayed in the golang's nanoserver-1809/Dockerfile. Notice the use of the USER instruction. The ContainerAdministrator must be used in order to set the system PATH:
# PATH isn't actually set in the Docker image, so we have to set it from within the container
USER ContainerAdministrator
RUN setx /m PATH "%GOPATH%\bin;C:\go\bin;%PATH%"
USER ContainerUser
# doing this first to share cache across versions more aggressively
Using Powershell as displayed in the golang's windowsservercore-ltsc2016/Dockerfile
RUN $newPath = ('{0}\bin;C:\go\bin;{1}' -f $env:GOPATH, $env:PATH); \
Write-Host ('Updating PATH: {0}' -f $newPath); \
[Environment]::SetEnvironmentVariable('PATH', $newPath, [EnvironmentVariableTarget]::Machine);
# doing this first to share cache across versions more aggressively
Both ways do work with recent Docker Desktop.
The ENV instruction is not going to work on Windows.
This is what I got working, but it doesn't seem ideal:
RUN setx /M PATH $($Env:PATH + ';C:\Foo\bin')

RUN powershell failing in docker build on windows 2019 server

I am running on Windows 2019 server.
I am getting an error whenever I invoke powershell from a dockerfile on docker build
Error is..
---> Running in 6efa29aa8a4a
The command 'powershell -Command DIR' returned a non-zero code: 3221226505
Dockerfile..
# escape=` (backtick)
FROM mcr.microsoft.com/windows/servercore:ltsc2019
RUN DIR
RUN ["powershell", "-Command", "DIR"]
COPY ./ app/
WORKDIR app
CMD [ "someapp", "somearg" ]
I have tried replacing cmd with powershell via
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN DIR
and the results are the same.
Thanks
Try running a dockerfile more like
FROM mcr.microsoft.com/windows/servercore/iis
RUN powershell -NoProfile -Command Remove-Item -Recurse
C:\inetpub\wwwroot*
WORKDIR /inetpub/wwwroot
COPY . /inetpub/wwwroot
maybe you gotta move your COPY command after the WORKDIR ?
Try different things out
Check to make sure you have update KB4532691 installed on your build machine (and host). The newest image of ltsc2019 (20/2020) has issues without it.
See https://hub.docker.com/_/microsoft-windows-servercore and https://support.microsoft.com/en-us/help/4542617/you-might-encounter-issues-when-using-windows-server-containers-with-t for more info

How to install a specific KB update to a Windows Server 2016 Docker container

I have a Windows Server 2016 Docker container and I want to apply a specific KB update to it. I wonder how to do it programmatically?
Your Dockerfile could look like this:
FROM microsoft/windowsservercore:ltsc2016
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Invoke-WebRequest "KB_URL" -OutFile update.exe -UseBasicParsing ; \
Start-Process -FilePath 'update.exe' -ArgumentList '--quiet', '--norestart' -Wait ; \
Remove-Item .\update.exe

In Docker (for Windows) How can I add registry entries in bulk while building my image?

I'm using Docker for Windows and building the docker image with a Dockerfile like this:
FROM mydockerhublogin/win2k16-ruby:1.0
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
RUN powershell -Command \
$ErrorActionPreference = 'Stop'; \
New-Item "HKLM:\Software\WOW6432Node\ExampleCom" -Force ; \
New-ItemProperty "HKLM:\Software\WOW6432Node\ExampleCom" -Name MenuLastUpdate -Value "test" -Force
RUN powershell -Command \
$ErrorActionPreference = 'Stop'; \
New-Item "HKLM:\Software\ExampleCom" -Force ; \
New-ItemProperty "HKLM:\Software\ExampleCom" -Name MenuLastUpdate -Value "test" -Force
# Run ruby script when the container launches
CMD ["C:/Ruby23-x64/bin/ruby.exe", "docker_ruby_test.rb"]
Note that I am adding some registry entries to the Windows registry which the code inside the container will access. While this method of adding registry entries is fine for a few entries, my requirement is to add dozens of entries required for my windows application. Is there a way to do this in a more concise manner?
Try creating a file for the your registry entry and copy that inside the container.
Then try running Invoke-Command -ScriptBlock {regedit /i /s C:\shared\settings.reg}
The following is the only way I could getting working using 4.8-windowsservercore-ltsc2019
COPY Registry/ChromeConfiguration.reg .
RUN reg import ChromeConfiguration.reg

Resources