How to run PGAdmin 4 Using Docker and Docker-Compose

Pinterest LinkedIn Tumblr

PGAdmin is a web-based GUI tool used to interact with the Postgres database sessions, both locally and remote servers as well. You can use PGAdmin to perform any sort of database administration required for a Postgres database.

pgAdmin 4 is designed to meet the needs of both novice and experienced Postgres users alike, providing a powerful graphical interface that simplifies the creation, maintenance and use of database objects.

In this guide, we are going to set up pgAdmin 4 in a container, the web based administration tool for the PostgreSQL database. 

Related content:


To follow along, ensure you have the following:

  1. Docker installed locally and permissions to use it to launch containers
  2. Docker compose is installed locally
  3. Basic knowledge of the command line

PostgreSQL Utilities

The PostgreSQL utilities pg_dumppg_dumpallpg_restore and psql are included in the container to allow backups to be created and restored and other maintenance functions to be executed. Multiple versions are included in the following directories to allow use with different versions of the database server:

  • PostgreSQL 10: /usr/local/pgsql-10
  • PostgreSQL 11: /usr/local/pgsql-11
  • PostgreSQL 12: /usr/local/pgsql-12
  • PostgreSQL 13: /usr/local/pgsql-13
  • PostgreSQL 14: /usr/local/pgsql-14

The default binary paths set in the container are as follows:

    'pg-14': '/usr/local/pgsql-14',
    'pg-13': '/usr/local/pgsql-13',
    'pg-12': '/usr/local/pgsql-12',
    'pg-11': '/usr/local/pgsql-11',
    'pg-10': '/usr/local/pgsql-10'

this may be changed in the Preferences Dialog.

Environment Variables

The container will accept the following variables at startup:


This is the email address used when setting up the initial administrator account to login to pgAdmin. This variable is required and must be set at launch time.


This is the password used when setting up the initial administrator account to login to pgAdmin. This variable is required and must be set at launch time.


This is the password used when setting up the initial administrator account to login to pgAdmin. This value should be set to docker secret in order to set the password. This variable is supported in docker swarm environment or while creating container with docker compose. PGADMIN_DEFAULT_PASSWORD or PGADMIN_DEFAULT_PASSWORD_FILE variable is required and must be set at launch time.


Default: [::]

Specify the local address that the servers listens on. The default should work for most users – in IPv4-only environments, this may need to be set to


Default: 80 or 443 (if TLS is enabled)

Allows the port that the server listens on to be set to a specific value rather than using the default.

Check more info here.

Running PGAdmin with Docker

You can run PGAdmin with docker run command like shown below:

➜ docker run -p 5080:80 \
    --name my-pgadmin \
    -e '[email protected]' \
    -v ~/pgadmin:/var/lib/pgadmin \
    -d dpage/pgadmin4:6.12

Unable to find image 'dpage/pgadmin4:6.12' locally
6.12: Pulling from dpage/pgadmin4
Digest: sha256:781369df9994157bbcee66d643fd2f70e996e95f86bbe9ec5aa17d7c4e7c3c43
Status: Downloaded newer image for dpage/pgadmin4:6.12


In the above command:

  • The -d instructs docker container to run as a detached process. It run container in background and print container ID
  • -p is for port mapping. We are instructing the container to expose the container port externally. Container port 80 is mapped to host port 5080. That means the service can be accessed through localhost:5432
  • The -v directive is used to mount volumes. In our case we are mounting the container volume /var/lib/pgadminto host path ~/pgadmin. Containers are ephemeral devices that will contain its data for the time it is running. Once a container is stopped, its data is lost. Mounting volumes ensures that the data is added to a host path that can be reused when the container is restarted.
  • The -e argument is for the environment variables. The supplied environment variables will be used to set up a default email and default password.

To check that our container is running as expected, use the docker ps command:

➜ docker ps

If you need to clean up the container when not in use, you can stop and remove the container using this command:

docker stop my-pgadmin

# Removing
docker rm my-pgadmin

To access PGAdmin, open your favourite browser and head over to then login with the username and password set up in environment variables.

Running PGAdmin with Docker-Compose

We can achieve the same functionality with docker-composeDocker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services.

Docker Compose allows you to define the service (Postgres in our case) with properties like the image to use, ports to expose, volumes to mount and environment variables.

Here is how we would use docker-compose to achieve the functionality above. Save this as docker-compose.yaml:

version: '3.9'

    image: dpage/pgadmin4:6.12
      - 5080:80
      - [email protected]
      - pgadmin_data:/home/rundeck/server/data


Now start the containers:

➜ docker-compose up -d
Creating network "blog_default" with the default driver
Creating blog_pgadmin_1 ... done

The commands:

  • up brings up the container
  • -d in a detached mode

Verify the container processes using the ps command:

➜ docker-compose ps

HTTP via Nginx

A configuration similar to the following can be used to create a simple HTTP reverse proxy listening for all hostnames with Nginx:

server {
    listen 80;

    location / {
        proxy_set_header Host $host;
        proxy_pass http://localhost:5050/;
        proxy_redirect off;


In this guide we managed to run PGAdmin 4 as a docker container in our system, we explored using the docker run command while passing the required arguments an alternative approach of simplifying the process with docker-compose.

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment