Docker container with specific MS Graph PowerShell versions.
Coz when I am troubleshooting why a specific cmdlet isn't working I'd like to easily switch to different version of the cmdlets instead of uninstalling/ reinstalling etc.
Here's what I do:
For the latest version:
docker build --progress=plain --no-cache . --network host -t graph-latest docker run -it --network host --rm \ -v /path/to/Scripts:/root/Scripts:ro \ -v /path/to/MoreScripts:/root/MoreScripts:ro \ -v /HOME/.config/powershell:/root/.config/powershell:ro \ graph-latest For a specific version (2.10.0 in this case):
version="2.10.0" docker build --progress=plain --no-cache . --network host --build-arg="GRAPH_VERSION=$version" -t graph-$version docker run -it --network host --rm \ -v /path/to/Scripts:/root/Scripts:ro \ -v /path/to/MoreScripts:/root/MoreScripts:ro \ -v /HOME/.config/powershell:/root/.config/powershell:ro \ graph-$version Also see the Notes section below.
If you just want to run the Docker image, assuming a version you want is already published under packages:
version="2.10.0" docker pull ghcr.io/rakheshster/docker-powershell-msgraph:$version docker run -it --network host --rm \ -v /path/to/Scripts:/root/Scripts:ro \ -v /path/to/MoreScripts:/root/MoreScripts:ro \ -v /HOME/.config/powershell:/root/.config/powershell:ro \ ghcr.io/rakheshster/powershell-msgraph:$version In this case I am pulling version 1.21.0. The version number is that of the Graph module.
Also see the Notes section below.
You may not need the --network host switch. I needed it coz of the way I was running Docker.
I use the -v switch to mount some of my folders containing scripts + the PowerShell profile into the container. This way everything is in place as expected. They are mounted RO in this case.
The docker run command will put you in a PowerShell prompt from which you can Connect-MgGraph and so on.
Also see my blog post where I talked about it first.
I have since made a Bash function like this:
function docker-graph() { docker run -it --network host --rm \ -v /path/to/Scripts:/root/Scripts:ro \ -v /path/to/MoreScripts:/root/MoreScripts:ro \ -v /HOME/.config/powershell:/root/.config/powershell:ro \ ghcr.io/rakheshster/powershell-msgraph:$1 } The --rm switch tells Docker to remove the container when I exit.
This way I can do docker-graph 2.10.0 and it will download and put me in that. If the image doesn't exist it errors:
$ docker-graph 2.9.0 Unable to find image 'ghcr.io/rakheshster/powershell-msgraph:2.9.0' locally docker: Error response from daemon: manifest unknown. See 'docker run --help'. The image is also available on DockerHub. Instead of ghcr.io/rakheshster/powershell-msgraph:xxx above use rakheshster/powershell-msgraph:xxx.
The original version of this container used the Ubuntu Powershell image from Microsoft as its base. Now it uses the CBL Mariner PowerShell image as its base. Reason for this switch is so I can create both amd64 and arm64 images - the latter is useful for those running Docker on M1 Macs.
Microsoft does not support arm64 on Ubuntu. There's no mention of arm64 with Linux anywhere actually, but I found the CBL Mariner images so I figure it is supported.