PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
44.58k stars 7.21k forks source link

PowerShell Docker image doesn't work on ARM without tags or with latest tag #20162

Open mikefrobbins opened 1 year ago

mikefrobbins commented 1 year ago

Prerequisites

Steps to reproduce

Use one of the following commands to run the PowerShell Docker container on an ARM based system such as a Mac M1 or M2 based system:

No tags:

docker run -it mcr.microsoft.com/powershell

Latest tag:

docker run -it mcr.microsoft.com/powershell:latest

Expected behavior

For the architecture to be automatically detected to run on either x64 or ARM without requiring specific tags to be specified.

Actual behavior

The Docker container appears to work, but when the first PowerShell command is run, it generates a terminating error because it's for the wrong architecture.

Error details

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested

qemu: uncaught target signal 11 (Segmentation fault) - core dumped

An error has occurred that was not properly handled. Additional information is shown below. The PowerShell process will exit.
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Regex1_Scan(RegexRunner, ReadOnlySpan`1)
   at System.Text.RegularExpressions.Regex.ScanInternal(RegexRunnerMode mode, Boolean reuseMatchObject, String input, Int32 beginning, RegexRunner runner, ReadOnlySpan`1 span, Boolean returnNullIfReuseMatchObject)
qemu: uncaught target signal 6 (Aborted) - core dumped

Environment data

docker version
Client: Docker Engine - Community
 Version:           24.0.5
 API version:       1.43
 Go version:        go1.20.6
 Git commit:        ced0996600
 Built:             Wed Jul 19 19:44:22 2023
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.21.1 (114176)
 Engine:
  Version:          24.0.2
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       659604f
  Built:            Thu May 25 21:50:59 2023
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Visuals

image

image

the-hotmann commented 1 year ago

Expected behavior

For the architecture to be automatically detected to run on either x64 or ARM without requiring specific tags to be specified.

Thats how properly tagged docker images should work. Specially when a manifest was provided and they have been properly build for the requested arches.

You can see there in this thread https://github.com/PowerShell/PowerShell/issues/20143 that PowerShell currently is lacking a lot when it comes to linux:

You are using no tag, which AFAIK fallsback to the tag latest, which you can see when pulling the image: Using default tag: latest. The Repo PowerShell does not have any arches listed on the tag latest - which is weird:

image

When running:

docker pull mcr.microsoft.com/powershell && docker image inspect mcr.microsoft.com/powershell | grep "Architecture"

On my AMD64 Server I get: "Architecture": "amd64",

When I run it on my linux based Apple Mini M1 I get: "Architecture": "arm",

Which is wrong, since it is a ARM64 chip. Testing with docker run -it mcr.microsoft.com/powershell (like the OP) results in:

$ docker run -it mcr.microsoft.com/powershell
exec /usr/bin/pwsh: exec format error
StevenBucher98 commented 1 year ago

cc @anamnavi for visibility

ovanekem commented 12 months ago

Although it does not resolve the original issue (using latest should support multiple architectures) I found out that there is version tagged as preview-mariner-2.0-arm64 which runs smoothly on my MacBook Pro M2, doing an inspect of the image shows indeed:

      "Architecture": "arm64",
        "Os": "linux",

It runs PS 7.4.0-preview:

/Users/olivier.vanekem % docker run -it mcr.microsoft.com/powershell:preview-mariner-2.0-arm64
PowerShell 7.4.0-preview.4
PS /> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.0-preview.4
PSEdition                      Core
GitCommitId                    7.4.0-preview.4
OS                             CBL-Mariner/Linux
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
the-hotmann commented 11 months ago

@ovanekem but this is of less value.

When I ru this on my Mac Mini M1 I get:

$ docker run -it mcr.microsoft.com/powershell:preview-mariner-2.0-arm64
PowerShell 7.4.0-preview.5
PS /> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.0-preview.5
PSEdition                      Core
GitCommitId                    7.4.0-preview.5
OS                             CBL-Mariner/Linux
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

The problem is, this command:

docker pull mcr.microsoft.com/powershell && docker image inspect mcr.microsoft.com/powershell | grep "Architecture"

still shows:

        "Architecture": "arm",

Which is wrong. My Mac Mini M1 is a arm64/aarch64 based CPU, not a arm based CPU.

rhubarb-geek-nz commented 10 months ago

I tested on a 64 bit Raspberry PI, and it is a 32 bit image, arch shows the real CPU

$ docker run -it --rm mcr.microsoft.com/powershell
PowerShell 7.4.0
PS /> dpkg --print-architecture
armhf
PS /> arch
aarch64
PS /> 
PS /> ldd  /usr/bin/pwsh
    libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xf7e60000)
    libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xf7e40000)
    libstdc++.so.6 => /lib/arm-linux-gnueabihf/libstdc++.so.6 (0xf7cb0000)
    libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xf7c50000)
    libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xf7c20000)
    libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xf7af0000)
    /lib/ld-linux-armhf.so.3 (0xf7ec4000)
LipJ01 commented 6 months ago

So the solution to accessing Powershell on MacOS (because apparently adding a wrapper for Set-MsolDomainFederationSettings inside Office 365 Admin Center to setup SSO through Google would be too easy) is to use mcr.microsoft.com/powershell:preview-mariner-2.0-arm64? Really? Am I the only one in the world that wants to use gmail and teams through the same account? What simple thing have I missed thats ended me up here? Apologies for cluttering this issue however I don't think I will be the only one that ends up here trying to get the same result.

rhubarb-geek-nz commented 6 months ago

So the solution to accessing Powershell on MacOS

You could use any Debian based Docker image and install PowerShell yourself, and there is no issue with you creating your own Dockerfile with that base image and adding any particular version of PowerShell.

Using no tags or latest tag is fraught with danger because you could end up with any wrong architecture, pre-release or bug-ridden version. Best practice is to specify the image you want, unless you actually don't care.

anamnavi commented 2 weeks ago

I'll look into this and adding a manifest for arm so that it's clearer experience