Manage Docker Desktop using Powershell

Containers have been around for almost a decade and can now be considered as the de-facto approach to application development. From a test and development MySQL server to the most famous internet services like Google and Netflix, containers are the way to run modern applications.

So, what is a container exactly? Containers are packages of software that contain all of the necessary elements to run in any environment. In this way, containers virtualize the operating system and run anywhere, from a private data center to the public cloud or even on a developer’s personal laptop.

The number of persons that are using containers has skyrocketed in recent years, making Docker Desktop the major platform for running containers on Windows and macOS systems.

Being a container user myself, I realized that a set of functions in Powershell would make my life a lot easier when it comes to the standard operations with Docker Desktop. I've put together all the functions that I needed at some point in time and the result is my Docker module. 

The functions in the module are separated into three major categories, container, image, and volume related. Let's take a look.

Container Operations

Returns an array of all the running containers on the system. Stopped containers are not shown by default, you can include them in the results using the -ShowAll switch. To get a specific container, use the -Name parameter (does not require the container to be running).

As the name suggests, you can use the New-DockerContainer function to create a new container.
The key parameters include:
  - Name: the name of the container to be created.
  - Image: the image to use (e.g. ubuntu).
  - Command: the command to execute when starting the container.
  - TTY: attach a pseudo-TTY.
  - MountVolumeName: the name of the volume to mount.
  - MountVolumePath: the path to mount the volume to, inside the container.

Start-DockerContainer / Stop-DockerContainer
Starts or stops a container using its name.

Removes a docker container. Use the -Force parameter to remove a running container.

Connect to a running container using the shell.

Image Operations

Returns an array that contains the docker images currently available in the system.

Removes an image from the system.

Volume Operations

Get a list of all the volumes in the system.

Create a new volume to be mounted to a container.

Remove a volume. The volume must not be in use.

The module is available for free on Powershell Gallery over here.

I'm planning to add more parameters and functions in the upcoming releases! Stay tuned!

Popular posts from this blog

Domain Controller Machine Password Reset

Configuring a Certificate on Exchange Receive Connector

Running Multiple NGINX Ingress Controllers in AKS