PGAdmin4 Docker Desktop Extension

Marcelo Ochoa
ITNEXT
Published in
4 min readMay 21, 2022

--

I am a big fan of Linux command line, so I have been using Docker from the command line for many years, but with the announcement of the general availability of Docker Desktop for Linux I decided to switch to this way of working with Docker, the way of Windows or Mac users ;)

Docker Desktop for Linux announcement at DockerCon 2022

https://docker.events.cube365.net/dockercon/2022/content/Videos/oZwAvW7auwoZYFSHF
https://docs.docker.com/desktop/linux/install/
https://docs.docker.com/desktop/linux/

It is important to take into account Why Docker Desktop for Linux runs a VM, among the things that can confuse the traditional Linux way I moved to Docker Desktop, is an amazing environment!!!.

Another important consideration is Docker Desktop Extensions and the ecosystem which these extensions make for developers.

With this upgrade on my environment I decided to build my first Docker Extension, this extension is for using PGAdmin4 inside Docker Desktop. This extension looks like:

PGAdmin4 Docker Extension in action

Why do I need a PGAdmin4 Docker Desktop Extension

Because many development stacks use PostgreSQL as backend databases, these stack could be PHP/Laravel, Java Spring Boot and many others, so usually developers need a tool to connect to these running databases to check data and make changes.

With above assumptions why not have a PGAdmin4 popular tool integrated to Docker Desktop?

If you think yes, go ahead with the next sections.

Install from Marketplace

Since Docker Desktop v4.11.0 PGAdmin4 Extension is available in Marketplace page, just click on + Add Extensions

find PGAdmin4 Extension and click Install

PGAdmin4 at Docker Desktop Marketplace

and that's all, PGAdmin4 icon its shown at left side menu (Extensions Beta).

Manual Installation

If you are using Docker Desktop v4.10.1 or less you can install just by executing:

$ docker extension install mochoa/pgadmin4-docker-extension:6.10.0
Extensions can install binaries, invoke commands and access files on your machine.
Are you sure you want to continue? [y/N] y
Image not available locally, pulling mochoa/pgadmin4-docker-extension:6.10.0
Installing new extension “mochoa/pgadmin4-docker-extension:6.10.0”
Installing service in Desktop VM…
Setting additional compose attributes
VM service started
Installing Desktop extension UI for tab “PGAdmin4”…
Extension UI tab “PGAdmin4” added.
Extension “PGAdmin” installed successfully

Note: Docker Extension CLI is required to execute above command, follow the instructions at Extension SDK (Beta) -> Prerequisites page for instructions on how to add it.

Using PGAdmin4 Docker Extension

Once the extension is installed a new extension is listed at the pane Extension (Beta) of Docker Desktop.

By clicking at PGAdmin4 icon the extension main window will show the extension in action

PGAdmin4 Welcome Screen

when the extension startup it may take some seconds, a progress indicator will wait for it

Progress Indicator bar

First login will ask you for a master password for pgAdmin4, fill it with your master password and click OK.

By clicking on Add New Server you can add PostgreSQL server running at Docker Desktop or externals, the IP for PostgreSQL running in Docker Desktop is available at the menu, Settings -> Resources -> Network -> Docker subnet, in my case is 192.168.65.0/24 so an internal IP for reaching out PostgreSQL containers running in Docker Desktop will be 192.168.65.2, also there is a DNS name which resolve above IP as host.docker.internal.

How to find internal bridge IP

Let see an example of PostgreSQL started using Docker Desktop Featured Images:

A PostgreSQL Docker instance started as features images

PostgreSQL Overview shows this sample URL:

postgres://postgres:postgrespw@localhost:55000

which means for a PGAdmin Add New Server:

  • Name: Test
  • Hostname/address: host.docker.internal
  • Port: 55002
  • Maintenance database: postgres
  • Username: postgres
  • Password: postgrespw

by choosing Save Password, the above password is stored at PGAdmin4 internal storage and will remain until you uninstall this extension. Let see in action:

Add new server dialog

You can add as many PostgreSQL databases are running as individual Docker Containers or services, but remember the 5432 PostgreSQL port must be exposed. Check first using Containers pane, for example:

Checking exposed port

Sources

As usual the code of this extension is at GitHub, feel free to suggest changes and make contributions, note that I am a beginner developer of React and TypeScript so contributions to make this UI better are welcome.

--

--