Debugging PowerShell from VS Code on Linux using Docker containers

Monday, Nov 13, 2017 2 minute read Tags: linux docker
Hey, thanks for the interest in this post, but just letting you know that it is over 3 years old, so the content in here may not be accurate.

I’ve previously blogged about running a Docker Linux container on Windows to run VS Code on Linux and at the time I was really just doing it because I wanted to work out if it was actually possible, which it was! But in reality it was really a solution just looking for a problem.

Well, good news, I have found the problem that this is a valid solution for! Well, as valid a solution as I can come up with at least.

One of my pet projects is a PowerShell module for managing different Node.js versions, called nvm. This little module has been floating around for a few years now, I add things to it whenever I find a problem, or someone reports one.

The other month someone raised an issue, the module didn’t work on OSX. Well I wasn’t surprised, I’d never tried it on OSX but Felix was willing to give it a go. After a bit of back and forth it was all up and running. We then worked on a few other steps that saw automated tests written and CI setup on AppVeyor and Travis-CI.

And then what’s next, well adding Linux support of course! It’s being tracked here. There was a problem though, an error is reported when running the tests, an odd error about version numbers. I figured that the error was coming something in the test framework but I don’t know where so I needed to do some investigation.

But how do you do that when a) PowerShell is running on Linux and b) I don’t run Linux?

Docker!

So I know you can run PowerShell in a Linux container and I previously proved I could run VS Code on a Linux container with X11 forwarding to Windows, so why don’t we combine them, install the PowerShell VS Code extension and debug the tests! It beats trying to work out how to setup remote debugging.

It was just a matter of taking Jessie’s VS Code Dockerfile, changing the FROM to be from microsoft/powershell and then you’re good to go!

Debugging PowerShell on Linux in VS Code in a Docker Container from Windows

Aww yeah! 😀

For the record I did find the cause of the bug, it was a type conversion issue due to the order of precedence in PowerShell equality tests within Pester, as reported here. Good to know JavaScript isn’t the only one with type conversion issues 😛