Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
.NET Core SDK Docker Images Contain PowerShell Core #1069
.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:
For the second example to work, on Linux, the
#!/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.
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:
I then attempted to install Nuget...which I attempted to install as follows:
Install-PackageProvider -Name NuGet -MinimumVersion 18.104.22.168 -Force
Then it threw the following error:
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.
Im experiencing the same. Could it be related to: OneGet/oneget#443
Also, on my local machine i have the
Thank you so much for adding powershell.
Also I notice unit testing is not working:
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.
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.