Run PowerShell Natively on Linux and Docker!

Microsoft just made a huge splash today, by announcing that PowerShell is now available on Linux! I created a launch video that demonstrates how to get PowerShell Core running inside a Docker container! You can see the video over on Microsoft’s MSDN Channel 9.

https://channel9.msdn.com/Shows/msftazure/Run-PowerShell-Natively-on-Linux-with-Docker

Check if PowerShell is Running in a Docker Container

If you’re writing a PowerShell script, and need to check to see if PowerShell is running inside a Docker Container, then you can use this simple function. It simply returns [bool] $true if it’s running inside a container, and [bool] $false if it’s not running inside a container!

function IsContainerized {
    [CmdletBinding()]
    param ()
    
    if ((Get-Content -Raw /proc/1/cgroup) -match 'docker') {
        $true
    } else {
        $false
    }
}
  • Pingback: Dew Drop - August 19, 2016 (#2312) - Morning Dew()

  • OlegM

    This is definitely awesome. I wasn’t aware that Powershell made its way to Linux. Any thought on how this will play out long term with Bash? All the rage few months back was bash coming to W10?

    • Hey Oleg, Bash isn’t an object oriented shell, so in my personal opinion, it’s only a stop-gap solution. PowerShell is definitely the way forward.

      Cheers,
      Trevor Sullivan