Skip to content

PowerShell installed as global tool with .NET 6 fails to run on Alpine 3.19 #20945

Closed

Description

Prerequisites

Steps to reproduce

Similar issue to #16532. Build and run the following Dockerfile:

FROM alpine:3.19

ENV \
    # Enable detection of running in a container
    DOTNET_RUNNING_IN_CONTAINER=true \
    # Set the invariant mode since ICU package isn't included (see https://github.com/dotnet/announcements/issues/20)
    DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true

RUN apk add --upgrade --no-cache \
        ca-certificates \
        \
        # .NET dependencies
        krb5-libs \
        libgcc \
        libintl \
        libssl3 \
        libstdc++ \
        zlib

# Install .NET SDK
RUN wget -O dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Sdk/6.0.417/dotnet-sdk-6.0.417-linux-musl-x64.tar.gz \
    && mkdir -p /usr/share/dotnet \
    && tar -C /usr/share/dotnet -oxzf dotnet.tar.gz \
    && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet

# Install PowerShell
RUN dotnet tool install --global PowerShell --version 7.2.17

ENTRYPOINT [ "/root/.dotnet/tools/pwsh" ]

Expected behavior

PowerShell starts and runs

Actual behavior

PowerShell 7.2.17
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

One or more errors occurred. (The type initializer for 'System.Management.Automation.TypeAccelerators' threw an exception.)
One or more errors occurred. (The type initializer for 'System.Management.Automation.TypeAccelerators' threw an exception.)
Cannot load PSReadline module.  Console is running without PSReadline.
Process terminated. The type initializer for 'System.Management.Automation.PSObject' threw an exception.
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSObject' threw an exception.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   --- End of inner exception stack trace ---
   at System.Management.Automation.PSObject.get_Properties()
   at System.Management.Automation.HostUtilities.GetDollarProfile(String allUsersAllHosts, String allUsersCurrentHost, String currentUserAllHosts, String currentUserCurrentHost)
   at Microsoft.PowerShell.ConsoleHost.DoRunspaceInitialization(Boolean skipProfiles, String initialCommand, String configurationName, Collection`1 initialCommandArgs)
   at Microsoft.PowerShell.ConsoleHost.DoCreateRunspace(String initialCommand, Boolean skipProfiles, Boolean staMode, String configurationName, Collection`1 initialCommandArgs)
   at Microsoft.PowerShell.ConsoleHost.CreateRunspace(Object runspaceCreationArgs)
   at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName)
   at Microsoft.PowerShell.ConsoleHost.Run(CommandLineParameterParser cpp, Boolean isPrestartWarned)
   at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)

Error details

No response

Environment data

Cannot get $PSVersionTable because PowerShell is not functional.

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Dec 18, 2023
  2. lbussell commented on Dec 18, 2023

    @lbussell
    Author

    /cc Aditya Patwardhan (@adityapatwardhan)

    Given the issue in the past was apparently the .NET RID not being available yet, I went ahead and filed some issues for that:

  3. lbussell commented on Jan 9, 2024

    @lbussell
    Author

    rhubarb-geek-nz I appreciate your investigation, but we aren't interested in using the Alpine-built .NET SDK or PowerShell for the official .NET container images. Your findings could be useful for someone who is interested in just getting things working though.

    /cc Aditya Patwardhan (@adityapatwardhan), according to the issues I filed (dotnet/core#9013, dotnet/runtime#96155) adding the RID to .NET isn't the fix since RIDs are all portable now. I'm not sure how that affects this issue, but can you take a look? This issue will block moving .NET SDK's floating tags to Alpine 3.19 since excluding PowerShell from Alpine x64 is a regression in functionality.

  4. lbussell commented on Jan 29, 2024

    @lbussell
    Author

    Aditya Patwardhan (@adityapatwardhan) Any update on this issue investigation?

  5. lbussell commented on Feb 13, 2024

    @lbussell
    Author

    I confirmed that this is still an issue with PowerShell v7.2.18.

  6. lbussell commented on Mar 6, 2024

    @lbussell
    Author

    I was looking at this again today and I found that adding the environment variable DOTNET_RUNTIME_ID=linux-musl-x64 allows PowerShell to start using a .NET 6 runtime! alpine-x64 and alpine.3.18-x64 also work.

    However there is a strange issue with the interactive terminal, it repeats all of the characters you type, as you type. For example, if I typed hello, the terminal would show: PS /> hhehelhellhello. The extra text does not have an effect on command output - if I type dotnet --list-runtimes and press enter, no matter what shows in the terminal, I will get the correct output. This is using .NET 6.0.27, Alpine 3.19, and PowerShell 7.2.18.

  7. lbussell commented on Apr 25, 2024

    @lbussell
    Author

    This should be checked again since dotnet/runtime#96155 is complete.

  8. lbussell commented on May 14, 2024

    @lbussell
    Author

    Confirmed this is fixed now.

    PS C:\s> docker run -it --rm mcr.microsoft.com/dotnet/sdk:6.0-alpine3.19 pwsh
    PowerShell 7.2.19
    Copyright (c) Microsoft Corporation.
    https://aka.ms/powershell
    Type 'help' to get help.
    
    PS /> echo "Hello!"
    Hello!
  9. moved this from Tracking to Done in .NET Dockeron May 14, 2024
  10. microsoft-github-policy-service commented on May 14, 2024

    @microsoft-github-policy-service
    Contributor

    📣 Hey Logan Bussell (@lbussell), how did we do? We would love to hear your feedback with the link below! 🗣️

    🔗 https://aka.ms/PSRepoFeedback

  11. removed
    Needs-Triage
    on May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions