Run PowerShell Natively on Linux with Docker

Download this episode

Download Video

Description

Have you turned into a skeleton, waiting for an object-oriented shell on Linux, that is easy to use, but is incredibly powerful and extensible? Have you been waiting to run PowerShell on Linux? Do you love Docker software containers? If so, then don't miss this awesome introduction to building your own custom Docker container image, that runs PowerShell natively on Ubuntu Linux!

The new, native PowerShell on Linux solution is called PowerShell Core, and sits on top of the Microsoft .NET Core framework that was released on June 27th this year!

During this information-packed video, we will:

  1. Provision an Ubuntu 16.04 Xenial Xerus LTS VM on the Microsoft Azure public cloud
  2. Install the Docker Engine on the brand new VM
  3. Write a custom Dockerfile using the cross-platform Visual Studio Code 
  4. Build a custom .NET Core / PowerShell Core Docker container image using a Dockerfile
  5. Run PowerShell Core on Linux natively, using our custom Docker image

Download the Dockerfile from the video, and build your own PowerShell Core Docker image!

Cheers,
Trevor Sullivan
Microsoft MVP
Docker Captain
https://twitter.com/pcgeek86
https://trevorsullivan.net
https://artofshell.com

Embed

Format

Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image
      Jacobjs01

      Rebuilding the docker image with --tag creates yet another image taking up more space on the hard drive. Is there a way to build with --tag on the first build pass?

    • User profile image
      pcgeek86

      @Jacobjs01: Hello -- yes. You only need to run it once. I just demonstrated the most simple way to build the image, but then built it again using --tag. Best practice: always use --tag. :)

      Cheers,
      Trevor Sullivan

       

       

    • User profile image
      lavermil

      Hello Trevor,

      Great video as always! I was wonder if you have played around yet with PowerShell for Linux and tried importing the Azure modules? While I am fully aware of Azure CLI, it is nice to be able to have options available in Linux.

      -Lance

    • User profile image
      JPW

      Can I use Vim instead of Visual Studio Code?

    • User profile image
      LeonMeijer

      @lavermil: The Azure modules are demonstrated here Managing Azure using PowerShell on Linux

    • User profile image
      pcgeek86

      @lavermil: Hello -- I did try to install the Azure Resource Manager (ARM) PowerShell module from the PowerShell Gallery, however this is currently not working.

      Cheers,
      Trevor Sullivan

    • User profile image
      pcgeek86

      @JPW: Yes, you can use any text editor that you'd like, to write your PowerShell scripts. Hopefully we see improved support for VIM over time!

      Cheers,
      Trevor Sullivan

    • User profile image
      p0nz

      Great video! Thank you for sharing.

    • User profile image
      pcgeek86

      @p0nz: Thanks for the kind comment. :D

      Cheers,
      Trevor Sullivan

    • User profile image
      garrirt

      Forgive my ignorance... but does this give me a portable version of PowerShell that I can run anywhere, say on WES2009?

      If not, how can I make PowerShell portable so that I can run it without installing anything else on WES2009?

      Thank you.

    • User profile image
      pcgeek86

      @garrirt: Hi there -- I'm not familiar with WES2009. What is that? The purpose of this video is to show how to run PowerShell natively inside Docker containers on Linux.

      PowerShell hasn't really been "portable" until just recently, so the chances of porting it to different operating systems is fairly restricted at present. As the .NET Core framework evolves, PowerShell will evolve along with it, and will be able to run on more and more platforms.

      Cheers,
      Trevor Sullivan

    • User profile image
      garrirt

      WES2009 = Windows Embedded Standard 2009 = Embedded WinXP SP3

      Would like to run PowerShell w/out installing the supporting environment.

      Any ideas?

    • User profile image
      prox2004

      If you are getting a key error when using the docker file it is likely that you are behind a firewall.
      Replacing this line:
      && apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893 \
      With this line:
      && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893 \

      Will allow your request to com on port 80.

      Thanks for the awesome video and build process.

    • User profile image
      bliz

      Excellent overview! Great job putting it together, and thanks for providing the source for the dockerfile.

      I just found a good article by Jessica Deen on running AzureRM modules on Ubuntu here (https://blogs.technet.microsoft.com/jessicadeen/azure/getting-started-with-powershell-core-and-azurerm-modules-on-ubuntu-and-os-x/)...

      It works inside PowerShellCore, and makes for a nice additional step at the end of your tutorial.

      Thanks!
      bliz 

    • User profile image
      pcgeek86

      @bliz: Awesome, thanks for sharing the link!

      Cheers,
      Trevor Sullivan

    • User profile image
      pcgeek86

      @prox2004: Thanks for the feedback and sharing the fix!

      Cheers,
      Trevor Sullivan

    • User profile image
      pcgeek86

      @garrirt: I'm not aware of any way to install PowerShell on that OS, sorry. My recommendation would be to upgrade to Windows Server 2012 R2 or later.

      Cheers,
      Trevor Sullivan

    • User profile image
      Smartmil8

      @Jacobjs01: So the question is whether the syscalls that Docker needs (for chroot and namespaces, among other things) were implemented or not. The answer is to that is likely "no". Docker requires fairly sophisticated (and Linux-specific) functionality for process and resource management, and process isolation. While it is probably possible to replicate all this on Windows, it would be a lot of work, and since the goal of this Windows feature seems to be running Linux userspace programs, it seems unlikely they did all the work (and kept it secret).

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.