Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Core SDK Docker Images Contain PowerShell Core #1069

Closed
richlander opened this issue Apr 18, 2019 · 11 comments

Comments

Projects
None yet
8 participants
@richlander
Copy link
Member

commented Apr 18, 2019

.NET Core 3.0 SDK Docker images now contain PowerShell Core

PowerShell Core has been added to the .NET Core 3.0 SDK Docker container images as part of .NET Core 3.0 Preview 4. PowerShell Core was added as a result of and resolves dotnet/dotnet-docker #360 . It has been added for both Linux and Nano Server container images, but only for SDK images.

PowerShell Core is a cross-platform (Windows, Linux, and macOS) automation and configuration tool/framework that works well with your existing tools and is optimized for dealing with structured data (e.g. JSON, CSV, XML, etc.), REST APIs, and object models. It includes a command-line shell, an associated scripting language and a framework for processing cmdlets.

You can try out PowerShell Core, as part of the .NET Core SDK container image, by running the following Docker command:

docker run --rm mcr.microsoft.com/dotnet/core/sdk:3.0 pwsh -c Write-Host "Hello Powershell"

There are two main scenarios that having PowerShell inside the .NET Core SDK container image enables, which were not otherwise possible:

Example syntax for launching PowerShell for a (volume-mounted) containerized build:

  • docker run -it -v c:\myrepo:/myrepo -w /myrepo mcr.microsoft.com/dotnet/core/sdk:3.0 pwsh build.ps1
  • docker run -it -v c:\myrepo:/myrepo -w /myrepo mcr.microsoft.com/dotnet/core/sdk:3.0 ./build.ps1

For the second example to work, on Linux, the .ps1 file needs to have the following pattern, and needs to be formatted with Unix (LF) not Windows (CRLF) line endings:

#!/usr/bin/env pwsh
Write-Host "test"

If you are new to PowerShell and would like to learn more, we recommend reviewing the getting started documentation.

Note: PowerShell Core is now available as part of .NET Core 3.0 SDK container images. It is not part of the .NET Core 3.0 SDK.

@SchoolforDesign

This comment has been minimized.

Copy link

commented Apr 20, 2019

­

@slayer991

This comment has been minimized.

Copy link

commented Apr 26, 2019

I'm unable to install anything from the PowerShell Gallery. First, I attempted to install the SharePointSDK from the PowerShell Gallery using

Install-Module -Name SharePointSDK -Force

Which then threw the following error:

NuGet provider is required to continue
This version of PowerShellGet requires minimum version '2.8.5.201' of NuGet
provider to publish an item to NuGet-based repositories. The NuGet provider
must be available in '' or ''. You can also install the NuGet provider by
running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'.
 Do you want PowerShellGet to install and import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Exception calling "ShouldContinue" with "2" argument(s): "Object reference not set to an instance of an object."
At /usr/share/powershell/.store/powershell.linux.x64/6.2.0/powershell.linux.x64/6.2.0/tools/netcoreapp2.1/any/Modules/PowerShellGet/PSModule.psm1:3115 char:8
+     if($Force -or $psCmdlet.ShouldContinue($shouldContinueQueryMessag ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NullReferenceException

Install-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
At line:1 char:1
+ Install-Module -Name SharePointSDK -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Install-Module], InvalidOperationException
+ FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module

I then attempted to install Nuget...which I attempted to install as follows:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

Then it threw the following error:

Install-PackageProvider : Unable to find repository with SourceLocation ''. Use Get-PSRepository to see all available repositories.
At line:1 char:1
+ Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (Microsoft.PowerShel\u2026tallPackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception
+ FullyQualifiedErrorId : RegisterPackageSourceRequired,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

Also this:

PS /> Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
PS />
NuGet provider is required to continue
This version of PowerShellGet requires minimum version '2.8.5.201' of NuGet provider to publish an item to NuGet-based repositories. The NuGet provider must be available in '' or ''. You
can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider
now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
PackageManagement\Install-PackageProvider : Unable to find repository with SourceLocation ''. Use Get-PSRepository to see all available repositories.
At /usr/share/powershell/.store/powershell.linux.x64/6.2.0/powershell.linux.x64/6.2.0/tools/netcoreapp2.1/any/Modules/PowerShellGet/PSModule.psm1:3128 char:21
+ ...     $null = PackageManagement\Install-PackageProvider -Name $script:N ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (Microsoft.PowerShel\u2026tallPackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception
+ FullyQualifiedErrorId : RegisterPackageSourceRequired,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

PackageManagement\Import-PackageProvider : No match was found for the specified search criteria and provider name 'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if theprovider exists on the system.
At /usr/share/powershell/.store/powershell.linux.x64/6.2.0/powershell.linux.x64/6.2.0/tools/netcoreapp2.1/any/Modules/PowerShellGet/PSModule.psm1:3134 char:21
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider

PackageManagement\Get-PackageProvider : Unable to find package provider 'NuGet'. It may not be imported yet. Try 'Get-PackageProvider -ListAvailable'.
At /usr/share/powershell/.store/powershell.linux.x64/6.2.0/powershell.linux.x64/6.2.0/tools/netcoreapp2.1/any/Modules/PowerShellGet/PSModule.psm1:3138 char:30
+ ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Microsoft.PowerShel\u2026.GetPackageProvider:GetPackageProvider) [Get-PackageProvider], Exception
+ FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider

Set-PSRepository : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
At line:1 char:1
+ Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Set-PSRepository], InvalidOperationException
+ FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Set-PSRepository

NOTE: I do have internet access from within the container which I validated by running a wget.

When I go to the command-line of the container, I noticed that get-psrepository and set-psrepository were not available.

Thanks.

@janstadt

This comment has been minimized.

Copy link

commented May 6, 2019

I'm unable to install anything from the PowerShell Gallery. First, I attempted to install the SharePointSDK from the PowerShell Gallery using

Install-Module -Name SharePointSDK -Force

Which then threw the following error:

NuGet provider is required to continue
This version of PowerShellGet requires minimum version '2.8.5.201' of NuGet
provider to publish an item to NuGet-based repositories. The NuGet provider
must be available in '' or ''. You can also install the NuGet provider by
running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'.
 Do you want PowerShellGet to install and import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Exception calling "ShouldContinue" with "2" argument(s): "Object reference not set to an instance of an object."
At /usr/share/powershell/.store/powershell.linux.x64/6.2.0/powershell.linux.x64/6.2.0/tools/netcoreapp2.1/any/Modules/PowerShellGet/PSModule.psm1:3115 char:8
+     if($Force -or $psCmdlet.ShouldContinue($shouldContinueQueryMessag ...
+        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NullReferenceException

Install-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
At line:1 char:1
+ Install-Module -Name SharePointSDK -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Install-Module], InvalidOperationException
+ FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module

I then attempted to install Nuget...which I attempted to install as follows:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

Then it threw the following error:

Install-PackageProvider : Unable to find repository with SourceLocation ''. Use Get-PSRepository to see all available repositories.
At line:1 char:1
+ Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (Microsoft.PowerShel\u2026tallPackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception
+ FullyQualifiedErrorId : RegisterPackageSourceRequired,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

Also this:

PS /> Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
PS />
NuGet provider is required to continue
This version of PowerShellGet requires minimum version '2.8.5.201' of NuGet provider to publish an item to NuGet-based repositories. The NuGet provider must be available in '' or ''. You
can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider
now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
PackageManagement\Install-PackageProvider : Unable to find repository with SourceLocation ''. Use Get-PSRepository to see all available repositories.
At /usr/share/powershell/.store/powershell.linux.x64/6.2.0/powershell.linux.x64/6.2.0/tools/netcoreapp2.1/any/Modules/PowerShellGet/PSModule.psm1:3128 char:21
+ ...     $null = PackageManagement\Install-PackageProvider -Name $script:N ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (Microsoft.PowerShel\u2026tallPackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception
+ FullyQualifiedErrorId : RegisterPackageSourceRequired,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

PackageManagement\Import-PackageProvider : No match was found for the specified search criteria and provider name 'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if theprovider exists on the system.
At /usr/share/powershell/.store/powershell.linux.x64/6.2.0/powershell.linux.x64/6.2.0/tools/netcoreapp2.1/any/Modules/PowerShellGet/PSModule.psm1:3134 char:21
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider

PackageManagement\Get-PackageProvider : Unable to find package provider 'NuGet'. It may not be imported yet. Try 'Get-PackageProvider -ListAvailable'.
At /usr/share/powershell/.store/powershell.linux.x64/6.2.0/powershell.linux.x64/6.2.0/tools/netcoreapp2.1/any/Modules/PowerShellGet/PSModule.psm1:3138 char:30
+ ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Microsoft.PowerShel\u2026.GetPackageProvider:GetPackageProvider) [Get-PackageProvider], Exception
+ FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider

Set-PSRepository : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
At line:1 char:1
+ Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Set-PSRepository], InvalidOperationException
+ FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Set-PSRepository

NOTE: I do have internet access from within the container which I validated by running a wget.

When I go to the command-line of the container, I noticed that get-psrepository and set-psrepository were not available.

Thanks.

Im experiencing the same. Could it be related to: OneGet/oneget#443

Also, on my local machine i have the Binary ModuleType module for PackageManagement whereas the 3.0 pre image has the Script ModuleType. Not sure if that makes any difference. I also tried to manually copy over nuget.exe and Microsoft.PackageManagement.NuGetProvider.dll without any luck. There is also this: https://www.reddit.com/r/PowerShell/comments/8f3dqr/cant_install_any_powershell_modules/ haven't tried disabling FIPS yet. Next on the list of things to try.

@MarcoMedrano

This comment has been minimized.

Copy link

commented May 28, 2019

Thank you so much for adding powershell.
I am having same issue trying to install modules and setting up the default package provider, tried many things to fix that but no luck.

Also I notice unit testing is not working:

dotnet test $PROJECT_NAME -l xunit --results-directory test-reports
Starting test execution, please wait...
vstest.console process failed to connect to testhost process after 90 seconds. This may occur due to machine slowness, please set environment variable VSTEST_CONNECTION_TIMEOUT to increase timeout.
@slayer991

This comment has been minimized.

Copy link

commented May 30, 2019

Can anyone from Microsoft respond with a status on when we may expect this to work? Having a fully functional .NET Core with a complete implementation of PowerShell core solves a lot of problems for people. Since the current implementation of PowerShell core inside of .NET core seems to be incomplete, we're kind of stuck in limbo despite the exciting announcement in this thread.

I work for a large enterprise and we run everything else we need to run inside linux-based containers and we can't even think about Windows containers until OpenShift 4. I'd love to move our reporting tools off our Windows server POSH hosts and I'm certain I'm not the only one that feels this way.

@MichaelSimons

This comment has been minimized.

Copy link
Collaborator

commented May 30, 2019

@adityapatwardhan - Can you help out with the issues reported here with installing modules and package providers?

@tholabrk

This comment has been minimized.

Copy link

commented May 30, 2019

I think I recall there being discussions about trimming Powershell in the dotnet image, to focus on the exact use case scenarios they wanted to support, I can't find this discussion at the moment though, maybe it was on twitter?

I can say though, that the dotnet docker image definitely makes use of some "custom build" of Powershell I can't exactly find much information about, as such I found that in order to support the scenarios above that it was easier to use the powershell image as a base, which uses the publicly released artifacts on Github, and add dotnet core on top of it.

Specifically I used the nanoserver-1809 DockerFile as a reference point to add on top of the powershell nanoserver image.

Note, that even so there will still be some quirky behaviour, have not taken a deep dive into it, but installing the SqlServer module will, for example, besides some warning and errors, result in a failure due it failing the digital signature check, obviously I was able to "fix" this by skipping the cert check, but obviously that's dangerous behaviour to do in general. (Please use this information responsibly)

Also when getting the module installed, I was also not able to fix the PSModulePath so that you could do "Import-Module SqlServer", instead I had to input the full path to the .psd1-file, e.g. c:\Users\ContainerUser\Documents\Powershell\Modules\SqlServer\SqlServer.psd1

Installing modules as ContainerAdministrator with an install scope of AllUsers might work since that is still in the PSModulePath, but I have not tested this so far.

@janstadt

This comment has been minimized.

Copy link

commented May 30, 2019

I think I recall there being discussions about trimming Powershell in the dotnet image, to focus on the exact use case scenarios they wanted to support, I can't find this discussion at the moment though, maybe it was on twitter?

I can say though, that the dotnet docker image definitely makes use of some "custom build" of Powershell I can't exactly find much information about, as such I found that in order to support the scenarios above that it was easier to use the powershell image as a base, which uses the publicly released artifacts on Github, and add dotnet core on top of it.

Specifically I used the nanoserver-1809 DockerFile as a reference point to add on top of the powershell nanoserver image.

Note, that even so there will still be some quirky behaviour, have not taken a deep dive into it, but installing the SqlServer module will, for example, besides some warning and errors, result in a failure due it failing the digital signature check, obviously I was able to "fix" this by skipping the cert check, but obviously that's dangerous behaviour to do in general. (Please use this information responsibly)

Also when getting the module installed, I was also not able to fix the PSModulePath so that you could do "Import-Module SqlServer", instead I had to input the full path to the .psd1-file, e.g. c:\Users\ContainerUser\Documents\Powershell\Modules\SqlServer\SqlServer.psd1

Installing modules as ContainerAdministrator with an install scope of AllUsers might work since that is still in the PSModulePath, but I have not tested this so far.

We also ended up building off of the powershell image as base, but it would be nice if .net core with pwsh allowed for installing a module provider to pull other dependencies down.

@adityapatwardhan

This comment has been minimized.

Copy link

commented May 30, 2019

PowerShell in the dotnet SDK images should support installing packages from gallery. I will have a look at this today.

@adityapatwardhan

This comment has been minimized.

Copy link

commented May 30, 2019

We just released PowerShell v7.0.0-preview.1 which is based on netcore3.0. It has the fix for OneGet/oneget#443.

@MichaelSimons I can send a PR for updating the PowerShell version today, if you are fine with it.

@MichaelSimons

This comment has been minimized.

Copy link
Collaborator

commented May 30, 2019

@adityapatwardhan, what is the release schedule for v7.0.0? We would want it to release prior to 3.0 if we take a dependency on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.