In this series, we’ve been working through the different ways to install PostgreSQL. In Part 3, we move into the Windows world and will install PostgreSQL as a Docker container. Unlike Part 2, where the host was a Linux machine, this time, the host is a Windows server.
The VM
I’ll use the same spec VM as in the last two posts, which is sufficient for demonstration purposes:
- 8-Core CPU
- 8GB RAM
- Windows Server 2022
As before, we’ll work through the official Docker documentation, which, of course, in this case refers to installing on Windows.
On Windows, Docker is provided as a GUI application called Docker Desktop, rather than a command-line utility like that which we are used to on Linux.
Install Docker
Firstly, we’ll download the installer and run the .exe file. Let’s leave the defaults in place, which will use WSL2 for the virtualization.

Now we’ll wait for the installer to run through…

After a couple of minutes, we see success and then have to restart the machine:

After a restart, there is a shortcut on the desktop to the Docker Desktop application, so let’s open that.

After reading the service agreement, we can accept, assuming we’re happy with the terms:

Now we have to log in. I have a personal account so I’ll use that:

We now get a warning that WSL needs updating (we specified v2 at the beginning) WSL v2 is a lightweight Linux virtual machine built into Windows that enables us to run Linux applications from within Windows.
The installer helpfully gives us the exact command we need to run:

Let’s run the command in an elevated command prompt:
wsl --update
We get a progress report while it is installing:

After a minute or so, we get a message that the update was a success:

After re-opening the Docker Desktop application, I get a message that virtualization support is not detected. As the Windows server I am installing this on is a virtual machine and WSL2 is also a virtual machine, we are installing a VM inside a VM. I had to enable nested virtualization for the VM in the hypervisor, something which is beyond the scope of this article. This may or may not be required, depending on your setup.

With that sorted (it required a VM reboot), once we open Docker Desktop, we get a message saying the engine is starting:

This takes a few minutes, but once complete, we are greeted with the container menu, of which there are none. This is no surprise given this is a fresh install.

The next job is to download the PostgreSQL image. If we go to the images tab, we can use the search at the top to find the image we want:

Let’s search for the PostgreSQL image and hit “pull”:

In the images tab, we can click the play button to create the container:

At this point, we need to pass some parameters, which are the same ones we provided when we set the container up in Linux in the last post. I’ll use the same values:

We can hit “run” to start the container, and we see a log of what is going on, the final line confirming the cluster is set up and ready to go:

A trip back to the containers tab confirms the container has been created and is running:

Connect
As we are on a Windows host, the Defender firewall will block connections inbound unless we set a rule to allow them. We can do this in PowerShell with:
New-NetFirewallRule -Name postgres -DisplayName postgres -Direction Inbound -Action Allow -LocalPort 5432 -Protocol TCP

Now, we should be able to register a server in pgAdmin and connect:

And we are in – we can see the default activity tab has come up as we connect to our cluster.

References / Further Reading
Docker, Inc – Install Docker Desktop on Windows
DualCoreDBA – Four Flavours of Postgres Install – Part 1
DualCoreDBA – Four Flavours of Postgres Install – Part 2
The PostgreSQL Docker Community – postgres Official Docker Image
