1

I am trying to build docker image through Azure DevOps Pipeline (Agent: Windows-latest), here is the Dockerfile.

FROM mcr.microsoft.com/windows/nanoserver:ltsc2022

WORKDIR C:/app

RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"&& SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" -Y
RUN choco install temurin17jre -Y
RUN refreshenv

ENTRYPOINT ["Cmd"]

The pipeline is failing with below error, not sure what went wrong can someone please help me,

Step 7/21 : RUN powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"&& SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" -Y
---> Running in e6831658776c
'powershell' is not recognized as an internal or external command,
operable program or batch file.
The command 'cmd /S /C powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New- Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"&& SET 
"PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" -Y' returned a non-zero code: 1
##[error]The process 'C:\Windows\system32\docker.exe' failed with exit code 1
Lovababu Padala
  • 2,415
  • 2
  • 20
  • 28
  • Powershell isn't included anymore in the nanoserver according [to Microsoft](https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/container-base-images#windows-server-core-vs-nanoserver). Hence, you'd have to install it into the container. https://stackoverflow.com/a/65105080/6336357 – Rick Rackow Aug 11 '23 at 11:33
  • Does this answer your question? [How to install Powershell Core in aspnet Nanoserver docker container?](https://stackoverflow.com/questions/65104246/how-to-install-powershell-core-in-aspnet-nanoserver-docker-container) – Rick Rackow Aug 11 '23 at 11:34

1 Answers1

0

Nanoserver doesn't include powershell by default (leaving out many bits is what makes it so small).

You could use a different base image:

FROM mcr.microsoft.com/powershell:lts-nanoserver-ltsc2022

See:

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • It solved powershell issue, my goal to install openjdk-17 on windows container, for some reason powershell script is failing with some odd error `encountered an error during hcs::System::CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2)` , even I had a same issue while trying install chocolatey. Any documentation or sample dockerfile to install OpenJDK on windows container. ? – Lovababu Padala Aug 11 '23 at 14:24
  • This is my RUN command, `RUN powershell Invoke-WebRequest -Uri https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.8%2B7/OpenJDK17U-jdk_x86-32_windows_hotspot_17.0.8_7.msi -OutFile C:\Temp\openjdk17.msi` – Lovababu Padala Aug 11 '23 at 14:26
  • Nanoserver doesn't support Windows Intaller, only APPX and WSA based installers. But you should be able to get the `.zip`, extract that and add the correct location to the `PATH` . – jessehouwing Aug 11 '23 at 16:12
  • Nanoserver is **VERY** barebones. – jessehouwing Aug 11 '23 at 16:13