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 \ -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, be sure to change it in THREE places below):
docker build --progress=plain --no-cache . --network host --build-arg="GRAPH_VERSION=2.10.0" -t graph-2.10.0 docker run -it --network host \ -v /path/to/Scripts:/root/Scripts:ro \ -v /path/to/MoreScripts:/root/MoreScripts:ro \ -v /HOME/.config/powershell:/root/.config/powershell:ro \ graph-2.10.0 Please see the Notes section below.
If you just want to run the Docker image, assuming a version you want is already published under packages:
docker pull ghcr.io/rakheshster/docker-powershell-msgraph:1.21.0 docker run -it --network host \ -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/docker-powershell-msgraph:1.21.0 In this case I am pulling version 1.21.0. The version number is that of the Graph module.
Please 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 \ -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/docker-powershell-msgraph:$1 } So I can do docker-graph 2.10.0 and it will download and put me in that. If the image doesn't exist in GHCR then it errors:
$ docker-graph 2.9.0 Unable to find image 'ghcr.io/rakheshster/docker-powershell-msgraph:2.9.0' locally docker: Error response from daemon: manifest unknown. See 'docker run --help'.