DEV Community

Cover image for Stop exposing every Docker database port: use a single SSH tunnel instead
Jawira Portugal
Jawira Portugal

Posted on Originally published at blog.jawira.com

Stop exposing every Docker database port: use a single SSH tunnel instead

If you work with multiple Docker Compose projects, you've probably encountered this problem: every project has its own database, and every database wants to use the same host port.

PostgreSQL wants 5432, MySQL wants 3306, and before long, you're dealing with port conflicts or maintaining a list of custom port mappings.

What if you could access all your Docker databases through a single SSH entry point, without publishing their database ports?

The idea: one SSH gateway for all your databases

Instead of publishing database ports individually, you can create a dedicated SSH container connected to a shared Docker network.

Your database containers join that network, making them accessible to the SSH container through Docker's internal DNS.

Your IDE or database client connects to the SSH server, and the SSH tunnel handles the rest.

The result:

  • No need to publish individual database ports.
  • No more host port conflicts between projects.
  • A single SSH entry point for all your local databases.
  • Your IDE can connect directly to database containers using their Docker service names.

I implemented this approach using Docker Compose, OpenSSH and PhpStorm.

Read the complete tutorial

I've documented the complete implementation, including:

  • The OpenSSH Docker Compose configuration.
  • Connecting multiple Docker Compose projects to a shared network.
  • Configuring PhpStorm to connect through the SSH tunnel.
  • An alternative approach using conventional port mapping.

Read the full article on my blog:

👉 https://blog.jawira.com/2026/09/15/docker-database-ports-ssh-tunnel.html

The complete SSH tunnel project is also available on GitHub:

👉 https://github.com/jawira/tunnel

Top comments (0)