On my latest project I’ve been debugging Windows Server 2016 & Windows Server 2019 issues using the
Microsoft Server Core
docker containers.
I’m also a huge fan of the (not-so) new
Windows Terminal
, and wanted to find a way to incorporate a “fresh debugging environment” into a new tab.
Windows Terminal Settings
Those of you that have already customised your Windows Terminal know that the “settings screen” is a JSON code block that opens in your default editor (VS Code for me).
It looks something like this:
Add your new Docker commands as Profiles
In the list of Windows Terminal “Profiles” you’ll see all the default ones it was able to detect on your system, normally PowerShell and cmd.exe.
To add a new profile, just copy one of the existing entries and change the
GUID
and the
name
values. I’ve prefixed my docker container profiles with a whale (🐳) so that I know it’s hosted in
docker
.
"guid"
:
"{a25a83da-5bd2-4c68-97b8-a8720a80cff7}"
,
"name"
:
"🐳 Windows Server 2016"
,
"commandline"
:
"docker run --rm -it --name windows-terminal-2016 mcr.microsoft.com/windows/servercore:ltsc2016 powershell"
,
"suppressApplicationTitle"
:
true
The key value here is the
commandline
argument! We can pass in any command that we want
cmd.exe
to run!
Breaking down the command value
"commandline"
:
"docker run --rm -it --name windows-terminal-2016 mcr.microsoft.com/windows/servercore:ltsc2016 powershell"
,
To break down the command, what we’re asking is:
launch
docker
,
ask it to
run
a container,
ask it to remove the container when it exits (
--rm
),
ask it to attach the standard inputs (
-it
),
give the container a name (
--name windows-terminal-2016
)
and then using this base image:
mcr.microsoft.com/windows/servercore:ltsc2016
run
powershell
to give us a prompt!
Yay, that’s it!
Small gotchas
Even though we asked Docker to remove the container when it exits, that only happens when you actually
exit
from Powershell in the container. If you close the tab (Ctrl+F4, or clicking the cross) then the container doesn’t catch the exit signal and keeps on running. This means that next time you try and load the “tab” it’ll fail with an “container with that name already exists”-error. You can avoid this error by removing the name from the command (it’ll automatically generate a distinct one), but I’d prefer it like this for now.
If you’re downloading a large container for the first time (or the container image has a significant update) this can lock up Windows Terminal until the image download is complete. I would recommend adding
--pull never
to the command if this is a problem for you.
Asking for the latest
servercore
image doesn’t work (
BY DESIGN
), so you’ll have to find your specific version at
on this page
and reference it explicitly!
I’ve set
suppressApplicationTitle
to
true
in order to leave our title-bar alone and for me to easily locate the debugging tab. It’ll have the whale 😁
Extending this logic
Knowing that you can run ‘any’ command, I’ve also added a divider to separate out my docker containers:
The ‘profile’ that I set up for the divider (
if it’s accidentally launched
) is this:
"name"
:
"---- Dockerised Containers ----"
,
"commandline"
:
"powershell -NoLogo -NoExit -Command
\"
& { Write-Warning 'Why did you launch me!? Ah well, here are all ya dockers:'; docker ps -as }
\"
"
I hope this helps if you’re looking for a quick and easy way to launch a dockerised debugging environment!
Author |
Pat Hermens
I'm Pat Hermens, an Australian that's spent a decent amount of time living & working in the Netherlands.
I am a .NET developer (
for the last 20 years or so
), a technical manager, a public speaker,
a happy husband and father, but most of all;
I'm just a nerd.
I'm currently a
Director of Software Engineering
at
Slalom Build
in
Sydney, Australia
,
and I was previously Development Manager at
Coolblue
in Rotterdam, NL.