Using PowerShell for Docker Confidence

It’s been a while since I’ve written. I went from writing approximately six posts per month to nothing since last May. That’s unheard of, but alas, it’s true. A lot has changed in that time, including starting a new job, where there isn’t time for working in PowerShell nearly as much. There is, however, a need for me to up my Docker game. I used it in the past as I opted to learn and work with a CI/CD pipeline. But, as I get deeper into Docker I thought that there might be some people out there with an understanding of PowerShell, that could use it to feel comfortable looking at Docker closer. So, that’s who this is for. If you’re a Docker pro, then the things discussed in this post will likely hold little value. For me, the opportunity to write about this will only cement the Docker concepts in my own brain. With that, and for those where this post makes sense, let’s begin.

The first thing you’re going to need is… well, Docker of course. It’s been just about forever since I installed it, so don’t expect much out of me. Okay fine. Windows folks, go to https://docs.docker.com/get-docker and download the Windows .exe package. This is going to include both the command-line, docker tool, and Docker Desktop. I’ve never really used Docker Desktop before, but I’m not going to lie, after opening it up a time or two recently, I’ve gone back to it. It serves as a nice visual interface in which to help solidify the Docker concepts of containers, images, and volumes. Keep it in mind, sure, but let’s open PowerShell now that Docker is installed, and run our first Docker command.

The first command we’re going to run is a docker pull command. This will download a Docker image from hub.docker.com. Think of an image as a set of instructions to create a container. It’s a standalone, executable package of goodness with all the code, and runtimes, and libraries, and tools needed to run an application. Anyway, let’s pull down our image using the full command of docker pull mcr.microsoft.com/powershell. You can always search at hub.docker.com for the image or images, you want. They’ll even include the full docker pull command for you!

Because I already had the latest, or most recent, version of the PowerShell Docker image, there was nothing for docker to pull for me. When your pull is complete, run docker image ls to see the image(s) you have. You can also open Docker Desktop to see them listed visually. It’s helpful, it really is. In the below image you can see that I have the last two most recent versions of the Docker PowerShell image.

I wasn’t going to do it originally, but I found an additional image of interest, so I downloaded it in order that I could include a couple of additional images — like pictures — in this post. I first downloaded a Python Docker image, as you can see, and then ensured it was included in my list of images.

Now we’re going to have Docker run the PowerShell image, and therefore create a container for us, from that image. Do this using docker run --interactive --tty mcr.microsoft.com/powershell. The --interactive --tty options could’ve been written as -i -t or, even -it. This will come in handy if you don’t know it already! Once the above command is executed, you’ll have a Powershell prompt inside the Powershell Docker container. I know right; it’s awesome! It’s a little Linux container running right there on your bare metal computer or VM, completely isolated from everything else going on. If you’re new to Docker, this may be the push you need to start learning it… before you need it.

Oh yeah, here’s a quick piece of potentially interesting information. Using docker run with the options (arguments) and Docker image name, and Docker will pull down the image if you don’t already have it!

Leave a Reply

Your email address will not be published. Required fields are marked *