Working in Parallels and Docker on the host

3 minute read article technology   leadership   azure   macos   docker   parallels   powerbi Comments

Yesterday I wrote about working in virtual machines, specifically Parallels on my Mac as well as a bit about Azure VMs. Since I think Parallels is the way I’m going, at least for now, I wanted to dive into a common scenario along with some of the issues I’ve experienced and how I got past those issues.

Docker on a Mac Host

I’m comfortable running Windows 11 in Parallels, and I’m comfortable with running Docker on my Mac, but sometimes getting them to talk to each other is a bit of a struggle.

There are times I need to do some things on my Mac and some things from the VM. For example, I may have the database running in Docker on my Mac, but need to connect to it from a Windows app in the VM, or I may have a web app running in Parallels but want to test it from Safari on my Mac.

Let’s take one of these examples and see how it works: Postgres running in Docker on the Mac host and connecting to it from Power BI Desktop in Parallels.

A tutorial on running PostgreSQL in Docker

Once Docker is running, pulling the Postgres image is as simple as

docker pull postgres

That will pull the latest image, which in my case, is what I want.

Running is as simple as:

docker run --name postgres -e POSTGRES_PASSWORD=passw0rd -d postgres

That starts a container instance named ‘postgres’ with a password of passw0rd running on the default port of 5432. If you need to change ports, use the -p parameter to map a local port to the port exposed from Docker (-p 5432:5432).

There are other parameters you can use if you want to run it interactively or if you want to mount a specific data volume, but for the purposes of this post, I’m going to leave both off.

pgAdmin

In order to manage the database instance that’s now running, it’s good to have something like pgAdmin which can also be run in Docker:

docker pull dpage/pgadmin4
docker run --name pgadmin -p 4202:80 -e PGADMIN_DEFAULT_EMAIL=foo@bar.com -e PGADMIN_DEFAULT_PASSWORD=passw0rd -d dpage/pgadmin4

Once it’s running, navigate to localhost:4202 and you’ll have access to pgAdmin on your local machine. Login with the email and password you provided.

pgAdmin login screen

In order to connect to the instance of PostgreSQL that’s running, use the built-in alias Docker gives you (host.docker.internal) with the correct port for you instance (remember, the default is 5432).

Register a new server in pgAdmin

At this point, it’s a vanilla PostgreSQL installation with no data, but I restored a sample database to make life easier for this post. See this repo.

Connecting to the host from Parallels

I’m documenting this for myself because so I’ll know where to look next time.

Ok, after all that setup, now I want to show how to connect to it from Windows 11 running in Parallels.

With shared networking enabled in Parallels Desktop for Mac (as opposed to the Pro or Business editions), machines are assigned to a specific subnet. The host gate is 10.211.55.1, the host machine is 10.211.55.2, my Windows VM is on .4.

For convenience, you can add this to your hosts file on Windows so you can refer to it by the name ‘host’ instead of the IP.

10.211.55.2 host

So, from Windows, I can browse to pgAdmin by navigating to http://10.211.55.2:4202

pgAdmin running in Docker on the Mac host being accessed from the Windows 11 VM

So, connecting to the instance of PostgreSQL in Docker is done in the same fashion. Here’s what it looks like in Power BI Desktop:

Power BI selecting a database to connect to

And then you specify the server and database

Power BI PostgreSQL server and database

and then the credentials

Power BI PostgreSQL credentials

Once you’re connected, do what you need to do in Power BI (or whatever you’re connecting from).

Of course, if you’re writing code and need a connection string:

Provider=PostgreSQL OLE DB Provider;Data Source=10.211.55.2:4202;location=example;User ID=postgres;password=passw0rd;timeout=1000;

Final Thoughts

Like I said at the start of this post, I wrote this as a reminder for myself the next time I need to connect from Parallels to something running in Docker on my host Mac.

I hope you found some value in this post!


A seal indicating this page was written by a human

Updated:

Comments