PowerShell core is the edition of PowerShell built on top of .NET Core. It is sometimes simplified to “CoreCLR”, though it technically includes CoreFX as well.
PowerShell Core is cross-platform, available on Windows, macOS, and Linux, thanks to the cross-platform nature of .NET Core. On PowerShell Core, $PSVersionTable.PSEdition is set to Core.
Do note that while PowerShell Core 6.0 is cross-platform, there is also a PowerShell Core 5.0/5.1 released exclusively as part of Nano Server. In this blog post, we’ll learn how to run PowerShell core in a docker container.
First of all, we need to search for PowerShell core related images that are available. So you can search by https://hub.docker.com or you can also search using the docker command.
Below is the command to use while searching from a bash prompt:
docker search powershell --no-trunc
where –no-trunc specifies that output should not be truncated. It should throw an output like below:
Here, we can see that many types of images are available. We would choose to go with the image named microsoft/powershell, because 1) In description we can see that it is officially release by Microsoft itself 2) It has highest number of stars rating.
Now, to pull the specified image, we can use below command:
docker pull microsoft/powershell
We can now see that docker will start pulling all associated intermediate layers and start creating the image:
Once its done, we should be able to see the image in docker images list:
Now, we can create a container by using below command:
docker run -it microsoft/powershell:latest powershell
If we now run command $PSVersionTable as shown above, we can clearly see that PSEdition is set to core. From now on, you can run the regular powershell core cmdlets.