Invoke-WebRequest "host unknown" in powershell version 7.2, 5.1 did work - powershell-7.2

I use a script in our intranet with ps 5.1:
Invoke-WebRequest -UseDefaultCredentials -Uri http://intra.mycompany.com/mysite
updating to powershell 7.2 it stopped working
Invoke-WebRequest -UseDefaultCredentials -AllowUnencryptedAuthentication -Uri http://intra.mycompany.com/mysite
It says "Invoke-WebRequest: The given host is unknown." How can I make this http-request work in ps 7?

Related

Dockerfile: Combined run statements don't work correctly?

I've encountered a fairly perplexing issue with a Dockerfile I'm working on.
I need to install nodejs into a Windows container. The following statements do this...
RUN powershell -Command Invoke-WebRequest -Uri "https://nodejs.org/dist/v12.18.0/node-v12.18.0-x64.msi" -OutFile "./node-v12.18.0-x64.msi";
RUN msiexec /i node-v12.18.0-x64.msi AGREETOLICENSE=yes ADDLOCAL=ALL /qn;
RUN powershell -Command Remove-Item ./node-v12.18.0-x64.msi;
In an attempt to optimise the size and number of layers, I tried changing it to this...
RUN powershell -Command Invoke-WebRequest -Uri "https://nodejs.org/dist/v12.18.0/node-v12.18.0-x64.msi" -OutFile "./node-v12.18.0-x64.msi"; \
msiexec /i node-v12.18.0-x64.msi AGREETOLICENSE=yes ADDLOCAL=ALL /qn; \
powershell -Command Remove-Item ./node-v12.18.0-x64.msi;
The reasoning was that it would then avoid caching a layer with the node installer in it.
This appears to work correctly, except then later in the Dockerfile when it runs a command which requires node, it complains that it's not installed.
I can't see any reason why this is happening. The two different versions should be equivalent, with the exception of having less layers.
I ended up doing the following...
SHELL ["powershell.exe", "-Command"]
RUN $ErrorActionPreference = 'Stop'; \
Invoke-WebRequest -Uri "https://nodejs.org/dist/v12.18.0/node-v12.18.0-x64.msi" -OutFile "./node-v12.18.0-x64.msi"; \
Start-Process msiexec.exe -Wait -ArgumentList '/i "node-v12.18.0-x64.msi" AGREETOLICENSE=yes ADDLOCAL=ALL /qn'; \
Remove-Item "./node-v12.18.0-x64.msi"
After that, everthing worked fine.
I suspect that one of the commands was failing, but due to the way I was calling it, an error wasn't being thrown.
I think powershell might be the default shell, but I set it anyway to improve clarity.

Runnin docker build generates the following error "unknown instruction: EXPAND-ARCHIVE"

I have to say that I'm new to Docker and Dockerfiles... I need to create a build that has a nano server and java installed.
I've created the following docker file, but I got the error below
Here's the file
# Installer image
FROM mcr.microsoft.com/windows/servercore:1909 AS installer
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Invoke-WebRequest -OutFile java.zip https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_windows-x64_bin.zip;`
Expand-Archive java.zip -DestinationPath java; `
And the error is
Error response from daemon: Dockerfile parse error line 8: unknown instruction: EXPAND-ARCHIVE
What am I doing wrong? I'm on a Windows Container runtime
Thanks
Microsoft's documentation now mention to use the \ to escape over multiple lines
RUN Write-Host "pwsh .bak copied across"; \
Get-ChildItem -Path /var/opt/mssql/backup \
Invoke-Sqlcmd -query "SELECT GETDATE() AS TimeOfQuery" \
Invoke-Sqlcmd -query "SELECT * from sys.databases" \
https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/manage-windows-dockerfile#escape-character
Changed it to the following and tested. the error is gone.
# Installer image
FROM mcr.microsoft.com/windows/servercore:10.0.14300.1030 AS installer
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';
$ProgressPreference = 'SilentlyContinue';"]
RUN Invoke-WebRequest -OutFile java.zip https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c853231432d94f001e99d882ca7/jdk-13.0.2_windows-x64_bin.zip;
CMD [ "Expand-Archive", "java.zip", "-DestinationPath java;" ]

How to Dockerize windows application

i have a windows application which I want to containerize. Its a windows desktop application (not web application). I did some searching and found very little about containerizing desktop application. The application which I want to containerize works fine on WindowsServerCore. I have Windowsservercore image on my machine.
I want to know how can I go about containerizing it. Any documentation or useful videos are available?
when i completed dockerfile can i interact with my application gui??? how???
You can find tons of example of WindowsServiceCore-based applications in StefanScherer/dockerfiles-windows
You need to write a Dockerfile (like for instance diskspd/Dockerfile where you copy/unzip/install the application you need.
FROM microsoft/windowsservercore:10.0.14393.1770
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ENV DISKSPD_VERSION 2.0.17
RUN Invoke-WebRequest $('https://gallery.technet.microsoft.com/DiskSpd-a-robust-storage-6cd2f223/file/152702/1/Diskspd-v{0}.zip' -f $env:DISKSPD_VERSION) -OutFile 'diskspd.zip' -UseBasicParsing ; \
Expand-Archive diskspd.zip -DestinationPath C:\ ; \
Remove-Item -Path diskspd.zip ; \
Remove-Item -Recurse armfre ; \
Remove-Item -Recurse x86fre ; \
Remove-Item *.docx ; \
Remove-Item *.pdf
ENTRYPOINT [ "C:\\amd64fre\\diskspd.exe" ]
That being said, a full GUI support for windowscoreserver is still requested:
"Create base container with full GUI support".

Error running erlang in Windows Container

I'm attempting to get RabbitMQ up and running inside a Windows container but without a whole lot of luck. I've copied into the container the installation directories for RabbitMQ and Erlang but when I attempt to run erl.exe I'm told that beam.smp.dll is not able to be loaded.
PS C:\Program Files\erl8.2\bin> .\erl.exe
Unable to load emulator DLL
(C:\Program Files\erl8.2\erts-8.2\bin\beam.smp.dll)
Running the same command on the same installation directory on the host machine works just fine. I've checked that the file exists and that the checksums match. My bet is that there is some subtile difference in how the container loads the file and how the host loads the file. I'm just not sure where to even start looking.
Here is my Dockerfile which works. I can connect to RabbitMQ and the logs show it is running correctly, and I can login to the management UI using the guest/guest login from my host using IP/hostname of container.
# start with this container as the base
FROM microsoft/windowsservercore
# erlang installer download url
ENV erlang_download_url "http://erlang.org/download/otp_win64_19.3.exe"
# erlang will install to this location and rabbitmq will use this environment variable to locate it
ENV ERLANG_HOME c:\\erlang
# rabbitmq version used in download url and to rename folder extracted from zip file
ENV rabbitmq_version "3.6.9"
# rabbitmq zip package download url
ENV rabbit_download_url "https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.9/rabbitmq-server-windows-$rabbitmq_version.zip"
# setup powershell options for RUN commands
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# download and install erlang using silent install option, and remove installer when done
RUN Invoke-WebRequest -Uri $env:erlang_download_url -OutFile erlang_install.exe ; \
Start-Process -Wait -FilePath .\erlang_install.exe -ArgumentList /S, /D=$env:ERLANG_HOME ; \
Remove-Item -Force erlang_install.exe
# download and extract rabbitmq, and remove zip file when done
RUN Invoke-WebRequest -Uri $env:rabbit_download_url -OutFile rabbitmq.zip ; \
Expand-Archive -Path .\rabbitmq.zip -DestinationPath "c:\\" ; \
Remove-Item -Force rabbitmq.zip
# remove version from rabbitmq folder name
RUN Rename-Item c:\rabbitmq_server-$env:rabbitmq_version c:\rabbitmq
# enable managment plugin
RUN c:\rabbitmq\sbin\rabbitmq-plugins.bat enable rabbitmq_management --offline
# tell rabbitmq where to find our custom config file
ENV RABBITMQ_CONFIG_FILE "c:\rabbitmq"
RUN ["cmd", "/c", "echo [{rabbit, [{loopback_users, []}]}].> c:\\rabbitmq.config"]
# run server when container starts - container will shutdown when this process ends
CMD "c:\rabbitmq\sbin\rabbitmq-server.bat"

Dockerize ASP Classic on IIS

Microsoft has been investing in running docker on windows with Docker Desktop for Windows. Is it possible to run a legacy ASP Classic application on IIS through Docker? How?
https://hub.docker.com/r/microsoft/iis/
I finally got this all working. It was a lot more complex than running a simple Dockerfile, as it was a site that was originally developed in 2002. There were modules that had to be downloaded and installed, web.config sections that needed to be unlocked, and ODBC data connections that had to be made. My final docker file looked like this - hope it helps the next person!
# escape=`
FROM mcr.microsoft.com/windows/servercore/iis
SHELL ["powershell", "-command"]
RUN Install-WindowsFeature Web-ASP; `
Install-WindowsFeature Web-CGI; `
Install-WindowsFeature Web-ISAPI-Ext; `
Install-WindowsFeature Web-ISAPI-Filter; `
Install-WindowsFeature Web-Includes; `
Install-WindowsFeature Web-HTTP-Errors; `
Install-WindowsFeature Web-Common-HTTP; `
Install-WindowsFeature Web-Performance; `
Install-WindowsFeature WAS; `
Import-module IISAdministration;
RUN md c:/msi;
RUN Invoke-WebRequest 'http://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi' -OutFile c:/msi/urlrewrite2.msi; `
Start-Process 'c:/msi/urlrewrite2.msi' '/qn' -PassThru | Wait-Process;
RUN Invoke-WebRequest 'https://download.microsoft.com/download/1/E/7/1E7B1181-3974-4B29-9A47-CC857B271AA2/English/X64/msodbcsql.msi' -OutFile c:/msi/msodbcsql.msi;
RUN ["cmd", "/S", "/C", "c:\\windows\\syswow64\\msiexec", "/i", "c:\\msi\\msodbcsql.msi", "IACCEPTMSODBCSQLLICENSETERMS=YES", "ADDLOCAL=ALL", "/qn"];
EXPOSE 8000
RUN Remove-Website -Name 'Default Web Site'; `
md c:\mywebsite; `
New-IISSite -Name "mywebsite" `
-PhysicalPath 'c:\mywebsite' `
-BindingInformation "*:8000:";
RUN & c:\windows\system32\inetsrv\appcmd.exe `
unlock config `
/section:system.webServer/asp
RUN & c:\windows\system32\inetsrv\appcmd.exe `
unlock config `
/section:system.webServer/handlers
RUN & c:\windows\system32\inetsrv\appcmd.exe `
unlock config `
/section:system.webServer/modules
RUN Add-OdbcDsn -Name "mywebsite" `
-DriverName "\"ODBC Driver 13 For SQL Server\"" `
-DsnType "System" `
-SetPropertyValue #("\"Server=XXXX.us-east-2.rds.amazonaws.com\"", "\"Trusted_Connection=No\"");
ADD . c:\mywebsite
I haven't tried, but it shouldn't be an issue to run classic ASP. The microsoft/iis image is based from the microsoft/windowsservercore image, which is a full Server Core install, and also includes 32-bit support.
The ASP feature won't be there by default, so your Dockerfile would have to start like this:
# escape=`
FROM microsoft/iis
SHELL ["powershell", "-command"]
RUN Install-WindowsFeature Web-ASP
(The escape and SHELL lines just make it easier to build Windows-friendy Dockerfiles, see Windows, Dockerfiles and the Backtick Backslash Backlash).
Then you would COPY in your ASP app folder, and run the rest of your IIS setup with PowerShell commands. This question has some good pointers, and this Dockerfile for an ASP.NET app shows how you can use PowerShell to configure websites.

Resources