Mar 17, 2025
Setting Up Traefik Proxy with PostgreSQL and pgAdmin in Docker Compose
Learn how to configure Traefik Proxy with PostgreSQL and pgAdmin using Docker Compose. Set up entry points, manage dependencies, and optimize database connections efficiently.
Author


Book a call
Table of Contents
In this post, I'll demonstrate how to include Traefik Proxy — a cloud native application proxy — in our Docker Compose file and use it in our architecture with PostgreSQL and pgAdmin service containers.
I've previously covered Traefik's principles in prior blogs —
As a baseline, I'm assuming you're familiar with Docker, Docker Compose & Traefik.
Let's get started —
I'll share the Docker Compose file, followed by a full analysis of what every line in our template represents.
Docker Compose
Details (of the content mentioned in Docker Compose file)
Replace
localhostwith your own domain or sub-domain intraefik,postgres&pgadminservicesChange config vars against these environment vars in
postgresservice —POSTGRES_USER,POSTGRES_PASSWORD&POSTGRES_DBChange config vars against these environment vars in
pgadminservice —PGADMIN_DEFAULT_EMAIL,PGADMIN_DEFAULT_PASSWORD&SCRIPT_NAMERun
docker-compose.ymlfile by using the commanddocker-compose up -dYour pgAdmin server should be up and running. Visiting http://localhost:1337/_admin/pgadmin, will show you your pgAdmin portal
You'll need to register a server in
pgAdminafter you successfully login into it with the configs values you used in yourdocker-compose.ymlfile - just remember to usepg_containeras the hostnameI'm using official docker images for PostgreSQL & pgAdmin
Analysing PostgreSQL service
The container name is your database hostname, from our template the database hostname is
pg_containerdepends_on: [traefik]means we want to wait tilltraefikservice is upportsexposes our postgres to accept incoming requests with the postgres port running inside your docker containervolumesmapping helps us to keep our data within the database to persist in our local machine. So, next time when we run our docker-compose from the same location - persisted data from the directory./postgres-datawill be utilised by our postgres service container and it won't redo all the installation stepsIn
volumes, you see I have commented out this line —# - ./init.sql:/docker-entrypoint-initdb.d/init.sqlIf you would like to do additional initialization in an image derived from this one, add one or more
*.sql,*.sql.gz, or*.shscripts under/docker-entrypoint-initdb.d(creating the directory if necessary)After the entrypoint calls initdb to create the default postgres user and database, it will run any
*.sqlfiles, run any executable*.shscripts, and source any non-executable*.shscripts found in that directory to do further initialization before starting the serviceWarning: scripts in
/docker-entrypoint-initdb.dare only run if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startupOne common problem is that if one of your
/docker-entrypoint-initdb.dscripts fails (which will cause the entrypoint script to exit) and your orchestrator restarts the container with the already initialized data directory, it will not continue on with your scripts
There are lots of other environment vars available in postgres docker image, you can find their references here - postgres
I do
healthcheckwith postgres container because it takes almost a minute to initialise for the first time and starts accepting connection requests once postgres container is up & this might break my backend apps which would need database connection in their start scriptsYou can find healthcheck references from the docker-compose's official documentation
Analysing pgAdmin service
depends_on: postgresThis statement means thatpgAdminservice depends onpostgresand waits until the healthy service status is received from the same container and this is how one should use thepostgresdepends in their backend app services as well.If not done as above, your backend will definitely fail most of the times which is not good for your final product
Almost all of the configs speaks for itself except env var
SCRIPT_NAMESince I have
traefik- I wanted to host my pgAdmin app on some route & here's how it's doneFirstly, to do this I had to move pgadmin on some route & you can do it by setting the
SCRIPT_NAMEvariableOnce that's done, now rewriting routes uri using traefik labels to
/_admin/pgadminwill do the job
Summary
After reading this article, you will have a fundamental grasp on how to setup Traefik Proxy with PostgreSQL and pgAdmin in your Docker Compose.
And I strongly advise everyone to have the "health check" docker-compose's index in your postgres service container to avoid unnecessary initialisation failures.
Source: This blog is authored by Faiz Ahmed, Principal Technical Consultant at GeekyAnts. Originally published on Hashnode: Read here.
Related Articles.
More from the engineering frontline.
Dive deep into our research and insights on design, development, and the impact of various trends to businesses.

Apr 23, 2026
From Manual Testing to AI-Assisted Automation with Playwright Agents
This blog discusses the value of Playwright Agents in automating workflows. It provides a detailed description of setting up the system, as well as a breakdown of the Playwright Agent’s automation process.

Apr 14, 2026
The Keyboard Bounce of Death: Handling Inputs on Complex React Native Screens
Fix the React Native ‘Keyboard Bounce of Death.’ Learn why inputs jump and how to build smooth, production-ready forms with modern architecture.

Apr 9, 2026
From RFPs to Revenue: How We Built an AI Agent Team That Writes Technical Proposals in 60 Seconds
GeekyAnts built DealRoom.ai — four AI agents that turn RFPs into accurate technical proposals in 60 seconds, with real-time cost breakdowns and scope maps.

Apr 6, 2026
How We Built an AI System That Automates Senior Solution Architect Workflows
Discover how we built a 4-agent AI co-pilot that converts complex RFPs into draft technical proposals in 15 minutes — with built-in conflict detection, assumption surfacing, and confidence scoring.

Apr 6, 2026
AI Code Healer for Fixing Broken CI/CD Builds Fast
A deep dive into how GeekyAnts built an AI-powered Code Healer that analyzes CI/CD failures, summarizes logs, and generates code-level fixes to keep development moving.

Apr 2, 2026
A Real-Time AI Fraud Decision Engine Under 50ms
A deep dive into how GeekyAnts built a real-time AI fraud detection system that evaluates transactions in milliseconds using a hybrid multi-agent approach.