Skip to main content

How to Set Up PgAdmin and Adminer Using Docker Compose?

If you are new to database management with Docker, this tutorial will guide you through setting up both PgAdmin and Adminer using Docker containers. By containerising these tools, you can quickly launch lightweight and portable database management environments without installing them directly on your operating system. This approach also makes it easier to manage configurations, updates, and multiple projects across different devices.

Prerequisite:

This tutorial is part of the Docker Series.


📚 View the Complete Docker Series

PostgreSQL Use case in


Preliminary: 
In this tutorial, I will walk you through how to download and install Docker and set up PgAdmin and Adminer using Docker Compose.

The file and folder for both containers are as follows:
1) PostgreSQL and PgAdmin

2) MySQL and Adminer

In the previous tutorial, I largely used SQLite as a database; however, SQLite is a lightweight database, and it may not be suitable for concurrent access by multiple users, especially in a web app. Therefore, more industry-based databases will be applied, which are PostgreSQL and MySQL databases.

What are MySQL and PostgreSQL?
MySQL and PostgreSQL are both popular open-source relational database management systems (RDBMS). They are used to store, organise, manage, and retrieve data for websites, applications, and software systems.

PostgreSQL - Supports advanced data types, JSON, GIS, and powerful indexing and is preferred for applications requiring strong data integrity and scalability.

MySQL - Known for being beginner-friendly and fast. Common in blogging platforms and web hosting environments,

Where and how to download and install both SQL tools?
In fact, I can directly download and install the respective tools as a desktop GUI to access both databases, such as the following:
PostgreSQL - PostgreSQL PgAdmin
MySQL - MySQL Workbench 

However, I will use Docker to set up both databases.

Why use Docker to set up PgAdmin and Adminer?
By using Docker, I can derive the following benefits:
  1. No Manual Installation,
  2. Keeps My System Clean,
  3. Easy Portability,
  4. Faster Setup for Development
  5. Easier Updates,
  6. Better for Learning and Testing and 
  7. Works Well with Database Containers
So I will set up PgAdmin for PostgreSQL and Adminer for MySQL

1) Download and Install Docker
Docker is a platform designed to help developers build, share, and run container applications.

Since Docker is an isolated container, if I need a single service, I write a Dockerfile; meanwhile, if I need multiple services, I use a Docker Compose YAML file. 


First, I need to download and install desktop Docker. It has multiple OSs to choose from, including Windows OS, Mac OS, and Linux OS. Since I used Windows 11, I downloaded the Windows OS, and I need to follow the step-by-step instructions to install Docker on the desktop. 

Before containerising the images, I need to open Docker Desktop.

2) Set up and configure PostgreSQL and PgAdmin
Then, the Docker Compose YAML file helps to define and manage multiple Docker containers in one place, and in my case, it contains two services: one is PostgreSQL, and the other is PgAdmin, as shown below:
name: PostgreSQL
services:
postgres:
image: postgres:16
container_name: postgres_db
restart: always
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
POSTGRES_DB: mydb
ports:
- "5432:5432"

pgadmin:
image: dpage/pgadmin4:latest
container_name: pgadmin
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin@example.com
PGADMIN_DEFAULT_PASSWORD: admin123
ports:
- "8080:80"

Both Postgres and PgAdmin require a login. 

For Postgres, the username is admin, the password is secret, and the database is mydb. Therefore, my connection would be as follows: postgresql://admin:secret@postgres:5432/mydb 

Meanwhile, PgAdmin uses the default email address, such as admin@example.com, and password, such as admin123, to log in to the PgAdmin interface to manage and monitor the PostgreSQL connection. 

The details: 
Container                  Image                                           Post 
PostgreSQL        postgres:16                                 localhost:5432 
PgAdmin            dpage/pgadmin4:latest             localhost:8080

PgAdmin is a specific web GUI tool only for PostgreSQL.

Here is my Dockerfile to install and run the image
# Use an official Python runtime as a parent image
FROM python:3.11-slim

# Set the working directory in the container
WORKDIR /app

# Install system dependencies required for building psycopg2 (if using non-binary)
RUN apt-get update && apt-get install -y \
libpq-dev \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Copy the requirements file into the container
COPY requirements.txt .

# Install the Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of your application code
COPY . .

# Command to run your application (adjust 'app.py' to your entry file)
CMD ["python", "app.py"]
  • FROM python:3.11-slim, it is optimised to be very small, containing only the minimal packages needed to run Python. This saves space and improves security.
  • WORKDIR /app creates a folder named /app inside the container and sets it as the "home base.",
  • RUN apt-get update && apt-get install -y ...:  This updates the list of available software and installs,
  • && rm -rf /var/lib/apt/lists/*, cleans up temporary files created during the installation, keeping the final Docker image size as small as possible.
  • RUN pip install --no-cache-dir -r requirements.txt: This installs all the libraries your app needs. not to store the downloaded installer files, which you don't need once the packages are installed.

The requirements.txt
psycopg2-binary
sqlalchemy
To run the Docker container, first open a bash terminal, navigate to the file directory, and execute the Docker command line below:
# Access the project directory
cd docker_postgre_pgadmin

# Pull and download the required container images
docker compose pull

# Create and start the containers
docker compose up
Once the container is running, I will go ahead and launch the browser and key in the URL and the web contents as follows:
http://localhost:8080/

If I need to stop the containerisation of the Docker command, as follows:
docker compose down

---------------------------------------------------------------------------------------------------------------------------------------------------

🎁 Get Your FREE Flask Cheat Sheet

Get more Flask, Python automation, Docker, and HTMX tutorials delivered to your inbox.

✓ Practical coding tutorials
✓ Automation tips for SMEs
✓ New project ideas and templates

Download my FREE Flask Cheat Sheet (PDF)


---------------------------------------------------------------------------------------------------------------------------------------------------


3) Set up and configure MySQL and Adminer
In fact, the same process also applies to MySQL and Adminer, except that the Docker Compose YAML is now different and shown below: 
name: MySQL

services:
  db:
    image: mysql:8.0
    container_name: mysql_db
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: mydb
      MYSQL_USER: myuser
      MYSQL_PASSWORD: mypass
    ports:
      - "3307:3306"   # Host port changed to 3307
    volumes:
      - db_data:/var/lib/mysql

  adminer:
    image: adminer
    container_name: adminer_ui
    restart: always
    ports:
      - "9000:8080"   # Adminer on port 9000
    environment:
      - ADMINER_DEFAULT_SERVER=db
    depends_on:
      - db

volumes:
  db_data:
Unlike PostgreSQL above, in MySQL, only MySQL requires logging in.

For MySQL, the username is myuser, the password is rootpass, and the database is mydb. Therefore, my connection would be as follows: mysql+mysqldb://myuser:mypass@db:3306/mydb 

The details: 
Container                Image                     Post 
MySQL                mysql:8.0           localhost:3306 
PgAdmin            adminer              localhost:9000 

P.S.: 
  • Host Port (9000): This is the port you use in your web browser to access the Adminer interface. You should navigate to http://localhost:9000. 
  • Container Port (8080): This is the internal port that the Adminer container is listening on inside its own environment. 
Adminer is a general database GUI; therefore, it can be applied to MySQL and PostgreSQL.

Here is my Dockerfile to install and run the image
# Use an official Python runtime as a parent image
FROM python:3.11-slim

# Set the working directory in the container
WORKDIR /app

# Install system dependencies for MySQL client and building C extensions
RUN apt-get update && apt-get install -y \
    default-libmysqlclient-dev \
    build-essential \
    pkg-config \
    && rm -rf /var/lib/apt/lists/*

# Copy the requirements file into the container
COPY requirements.txt .

# Install the Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of your application code
COPY . .

# Command to run your application
CMD ["python", "app.py"]
The Dockerfile is similar to PostgreSQL, except that the MySQL installation is different: 
  • default-libmysqlclient-dev (or libmariadb-dev): install mysqlclient. Without this, the installation would fail because it cannot find the necessary "hooks" to communicate with the MySQL server. 
  • build-essential: A package that installs a bundle of necessary tools for compiling software. 
  • pkg-config: A helper tool that makes it easier for the installer to find where the MySQL libraries are located on the system. 
  • && rm -rf /var/lib/apt/lists/*: By deleting this folder, you significantly reduce the size of your final Docker image, making it faster to upload and download. 

 The requirements.txt
mysqlclient
sqlalchemy

To run the Docker container, first open a bash terminal, navigate to the file directory, and execute the Docker command line below:
# Access the project directory
cd docker_postgre_pgadmin

# Pull and download the required container images
docker compose pull

# Create and start the containers
docker compose up
Once the container is running, I will go ahead and launch the browser and key in the URL and the web contents as follows:
http://localhost:9000/

If I need to stop the containerising of the Docker command, as follows:
docker compose down
Bonus
(i) SQLite vs PostgreSQL
Let us understand the differences among SQLite and PostgreSQL.

Basically, in my tutorial, I largely use SQLite, as it comes with Python. However, SQLite had its limitations. 

It is file-based, and therefore it is lightweight. But when I create a web app, it is not my preferred choice, as it will lock if multiple users log in or access the database concurrently. It could not facilitate reading and writing by different users at the same time. Only when the user completes the other can they access it. The most common usage is a desktop app for only a single user.

Therefore, for a web app, more robust databases come in to fit the capacity, such as PostgreSQL and MySQL. Since they are server-based, with their ports. Therefore, it allows multiple users to log in and access at the same time without locking the database. It is widely used in the industry, such as WordPress or complex data analytics.

(ii) PostgreSQL and MySQL cloud hosting
Most cloud storage supports either one or both database servers

Since not every platform supports both databases, the level of support may also differ. Even though there are supported ones, some may be deployed by Docker, and others are not.

Therefore, choosing the right platform is very important. Only Render and DigitalOcean support Docker deployment. Therefore, my tutorial will use Render as an example. However, I will also use PythonAnywhere, as it is dedicated to Python Flask for simple web app deployment. 

Besides those listed above, you may also deploy on a popular hosting provider. Such as:
  1. Amazon Web Services (AWS),
  2. Google Cloud Platform (GCP),
  3. Microsoft Azure
They provide a free trial as well, however, subject to terms and conditions. Their deployment might be a little bit complex, especially for a beginner. Therefore, I will not be included in my tutorial.

Final Wrap-up: 
In this tutorial, you learned how to quickly deploy PgAdmin and Adminer using Docker containers for a cleaner, more portable, and beginner-friendly database management setup. With Docker, you can simplify installation, reduce system clutter, and create reusable environments for development and testing. Whether you are managing MySQL or PostgreSQL databases, containerising your tools helps streamline your workflow and makes database administration much more convenient.

Published: May 2026
Last Updated: Jul 2026
---------------------------------------------------------------------------------------------------------------------------------------------------
Thanks for reading! 

If you haven't subscribed yet, join my newsletter to receive future Python and Flask tutorials.

-----------------------------------------------------------------------------------------------------------------------------
Need a similar system for your business? 
I build custom Flask web applications and Python automation solutions for SMEs and solopreneurs. 


-----------------------------------------------------------------------------------------------------------------------------

About the Author

Kelvin Loh is a Python developer focused on Flask, desktop applications, and business automation solutions. He shares practical tutorials and real-world coding projects to help developers and small businesses build useful applications.


Comments

Popular Posts

How to Build an Audiobook Workflow Desktop System with Python?

In this tutorial, we will build a simple audiobook player using Python and CustomTkinter. You will learn how to convert text into speech using gTTS and play it with PyGame. We will also implement play, pause, and stop controls, like those in a real audio player. By the end, you will have a clean and functional desktop audiobook app. Prerequisite: This tutorial is part of the standalone tutorial. 📚 View the standalone tutorial Preliminary   Before I begin, it is recommended to activate the virtual environment before installing the relevant dependencies. python -m venv venv venv\Scripts\activate pip install customtkinter pillow gTTS pygame CTkMessagebox pypdf Then, the following steps include setting up the file structure, app.py, and two additional folders: the uploads and media folders. The media folder contains the icons necessary to build the app; there are read, pause, and stop icons, as shown on the diagram. Step 1: Build up the app interface I have 4 sections here: the...