Skip to content

Instantly share code, notes, and snippets.

@mattbell87
Last active December 15, 2020 01:11
Show Gist options
  • Select an option

  • Save mattbell87/f085dfb1d8ff4a019fc03c5075dca426 to your computer and use it in GitHub Desktop.

Select an option

Save mattbell87/f085dfb1d8ff4a019fc03c5075dca426 to your computer and use it in GitHub Desktop.
Use docker for powershell on linux

Powershell on Linux with Docker

This is the method I used to run Powershell on Alpine Linux as there was no official repo available (you can only install manually). So here I'm using Docker to automatically provide the latest version of Powershell.

With this you can run Powershell scripts on your host (without being in a docker container shell), just use the normal pwsh command line paramaters.

pwsh my-script.ps1

Installing

Step 1: Install Docker

Step 2: Download to your /usr/local/bin folder:

sudo wget -O /usr/local/bin/pwsh "https://gist.githubusercontent.com/mattbell87/f085dfb1d8ff4a019fc03c5075dca4
26/raw/472ee1af630350513185a6df96e9fb1e9caf3d19/pwsh.sh"

Step 3: Mark as executable:

sudo chmod +x /usr/local/bin/pwsh
#!/bin/sh
# Save me as /usr/local/bin/pwsh and chmod +x
docker run -v /:/host -w /host/$PWD -it mcr.microsoft.com/powershell pwsh "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment