Docker Compose Production Hardening – pgAdmin Service Review

Docker Networking

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

  1. 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 the nat table's PREROUTING chain, so the packet is forwarded to the container through FORWARD. ufw filters INPUT, 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.
  2. The image floated. With :latest, any docker compose pull could upgrade pgAdmin against the existing pgadmin_data volume 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 at REL-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 4000 on the server lists only 127.0.0.1:4000.
  • curl http://<server-public-ip>:4000 from another machine fails.
  • docker compose -f docker-compose-prod.yml ps shows pgadmin4 healthy 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

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.