Access Loopback-Bound Docker Admin Services via SSH Tunneling
Goal
Make a containerized admin web interface (such as pgAdmin4) in Docker Compose listen only on the host's loopback interface (127.0.0.1), pin its image, and reach it from an administrator workstation through an encrypted SSH tunnel.
Prerequisites
- A remote Linux server running Docker Engine 28.3.3 or later (earlier 28.x releases could expose loopback-published ports after a firewalld reload: CVE-2025-54388) and Docker Compose.
- SSH key-based access to the server (
user@your-server) with TCP forwarding allowed insshd_config(AllowTcpForwarding yes, the OpenSSH default).
Steps
1. Find the Image Version the Server Runs
Pin the version that is already running, so the persistent volume isn't upgraded or downgraded by the change. On the server:
docker inspect --format '{{index .RepoDigests 0}}' \
"$(docker compose -f docker-compose-prod.yml images -q pgadmin4)"
This prints elestio/pgadmin@sha256:<digest>. Find the release tag with that digest on Docker Hub, or check pgAdmin's Help → About. To get the digest of a given tag instead:
docker buildx imagetools inspect elestio/pgadmin:REL-9_18
2. Bind the Port to 127.0.0.1 and Pin the Image
In docker-compose-prod.yml, prefix the host port with 127.0.0.1: and pin the tag and digest (see Container Image Version Pinning vs Mutable Tags):
services:
pgadmin4:
image: elestio/pgadmin:REL-9_18@sha256:<digest>
restart: unless-stopped
env_file:
- ./.env
environment:
PGADMIN_LISTEN_PORT: 80
GUNICORN_TIMEOUT: 300
ports:
- "127.0.0.1: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
Replace REL-9_18 and <digest> with the values from step 1.
3. Apply the Updated Compose Configuration
Recreate the service so Docker replaces the wildcard binding with the loopback one:
docker compose -f docker-compose-prod.yml up -d pgadmin4
4. Open an SSH Local Port-Forwarding Tunnel
From your workstation, forward local port 4000 to 127.0.0.1:4000 on the server. -N opens the tunnel without starting a remote shell:
ssh -N -L 4000:127.0.0.1:4000 user@your-server
Then open http://localhost:4000 in your browser. Traffic between your workstation and the server travels inside the encrypted SSH session. Stop the tunnel with Ctrl+C.
Verify
- Loopback-only binding on the server:
The local address column showsss -tlnp | grep 4000127.0.0.1:4000, and not0.0.0.0:4000,[::]:4000or*:4000. - External access blocked: from another machine, without the tunnel,
curl http://<server-public-ip>:4000fails withConnection refusedor times out. - Pinned image running:
docker compose -f docker-compose-prod.yml images pgadmin4shows the pinned tag.
Troubleshooting
channel 2: open failed: connect failed: Connection refusedwhen browsinghttp://localhost:4000: Check thatpgadmin4is running and healthy (docker compose -f docker-compose-prod.yml ps) and that Gunicorn has finished starting on port80.bind [127.0.0.1]:4000: Address already in useon your workstation: Another local process uses port4000. Pick a free local port:ssh -N -L 14000:127.0.0.1:4000 user@your-server, then browse tohttp://localhost:14000.manifest unknownondocker compose pull: The tag doesn't exist. Check the exact name on Docker Hub:REL-8_14, for example, was never published.
References
- Docker Compose Specification: ports - Publishing a container port on a specific host interface (
127.0.0.1). - OpenSSH ssh(1) Manual Page (-L, -N) - Local TCP port forwarding over SSH.
- OSV: CVE-2025-54388 - Why the Docker Engine minimum version matters (last checked 2026-10-23).
- Docker Compose Production Hardening – pgAdmin Service Review - Lab that motivated this procedure.
- Docker Port Binding and Host Firewall Bypass - Why wildcard port bindings bypass
ufw.