Docker Compose Production Hardening – pgAdmin Service Review
Goal
Review the pgadmin4 service in my production docker-compose-prod.yml and fix what exposes it to the internet or makes its deployments unpredictable.
Setup
The service as it was:
pgadmin4:
image: elestio/pgadmin:latest
restart: unless-stopped
env_file:
- ./.env
environment:
PGADMIN_LISTEN_PORT: 80
GUNICORN_TIMEOUT: 300
ports:
- "4000:80"
volumes:
- pgadmin_data:/var/lib/pgadmin
depends_on:
db:
condition: service_healthy
healthcheck:
test: [ "CMD", "wget", "-O-", "http://localhost:80/misc/ping" ]
interval: 30s
timeout: 10s
retries: 3
Steps and findings
- The admin panel was on the internet.
"4000:80"publishes port 4000 on every interface, IPv4 (0.0.0.0) and IPv6 ([::]). Docker rewrites the destination in thenattable'sPREROUTINGchain, so the packet is forwarded to the container throughFORWARD. ufw filtersINPUT, which the packet never reaches, so ufw doesn't block it. pgAdmin also served plain HTTP, so logins and queries crossed the network unencrypted. Fix: publish on loopback only ("127.0.0.1:4000:80") and reach it through an SSH tunnel. - The image floated. With
:latest, anydocker compose pullcould upgrade pgAdmin against the existingpgadmin_datavolume without a change in Git. Fix: pin a release tag and its digest. The tag documents the version; the digest is what actually stops a re-pushed tag from changing what runs. Pin the version the server already runs, so the volume isn't downgraded. (REL-8_14, my first choice, doesn't exist on Docker Hub: the 8.x series ends atREL-8_13.)
The two changed lines:
pgadmin4:
image: elestio/pgadmin:REL-9_18@sha256:<digest> # was: elestio/pgadmin:latest
ports:
- "127.0.0.1:4000:80" # was: "4000:80"
The full service definition and the steps to find the running version and its digest are in the SSH tunneling how-to.
Controls verified
-
ss -tlnp | grep 4000on the server lists only127.0.0.1:4000. -
curl http://<server-public-ip>:4000from another machine fails. -
docker compose -f docker-compose-prod.yml psshowspgadmin4healthy on the pinned image. - Docker Engine is 28.3.3 or later (see the CVE-2025-54388 caveat in Docker Port Binding and Host Firewall Bypass).
References
- Docker Docs: Packet filtering and firewalls - How Docker programs
iptablesand why published ports bypass ufw. - Docker Compose Specification: ports - Short-syntax port mappings with an explicit host IP (
127.0.0.1:HOST:CONTAINER). - Docker Compose Specification: image - Image references, including
tag@digest. - Docker Hub: elestio/pgadmin tags - Available release tags (last checked 2026-10-23: latest 9.x tag
REL-9_18, noREL-8_14).
Review cards
Flashcard Why does a port published as `"4000:80"` stay reachable from the internet while ufw denies port 4000?
Docker rewrites the destination in nat PREROUTING, so the packet is forwarded to the container
through the FORWARD chain. ufw's rules sit on INPUT, which that packet never goes through.
Flashcard What does publishing a port as `"127.0.0.1:4000:80"` change, and how do you still reach the service remotely?
The host only listens on loopback, so other machines can't connect. You reach it through an SSH
local forward (ssh -N -L 4000:127.0.0.1:4000 user@server), which also encrypts the traffic.
Flashcard Why can a routine `docker compose pull` break a stateful service that uses `:latest`?
:latest moves to each new release, so the pull can bring a new major version that no longer
works with the data already in the service's volume, with nothing changed in Git.
Quiz The publisher's registry account is compromised and the attacker re-pushes existing tags. Which image reference still runs the image you reviewed?
-
elestio/pgadmin:latest -
elestio/pgadmin:REL-9_18 -
elestio/pgadmin:REL-9_18@sha256:…
Tags are mutable pointers, release tags included. Only the digest names one exact image.
Flashcard What does pinning an image cost you, and how do you pay that cost?
You stop getting security fixes automatically. You need a deliberate update path: a bot like Renovate or Dependabot, or a scheduled check, that proposes the bump so it gets tested first.