Skip to content

docker-compose: stop exposing MariaDB on the host, add explicit network - #2143

Open
ugurcihan wants to merge 1 commit into
steve-community:masterfrom
ugurcihan:fix/1933-compose-network-hardening
Open

ugurcihan wants to merge 1 commit into
steve-community:masterfrom
ugurcihan:fix/1933-compose-network-hardening

Conversation

@ugurcihan

Copy link
Copy Markdown

Addresses part of #1933.

Changes

  • Removed ports: 3306:3306 on the db service. The app container never needed it on the host network — it reaches the database as mariadb over the compose network (now via an explicit network alias instead of the legacy links: mapping). Exposing the database port to the host was unnecessary surface area.
  • Added an explicit steve-net bridge network for db↔app traffic, replacing the implicit default network + legacy links:.

Testing

Tested end to end with docker compose up --build:

  • App builds and starts: Started SteveApplication in 14.886 seconds
  • App connects to the db over steve-net (HikariPool/jOOQ initialize against MariaDB successfully)
  • App is reachable on host port 8180 (302, expected pre-login redirect)
  • db is no longer reachable from the host — confirmed via docker compose ps, no host port binding shown on the db service (only 3306/tcp internal)

Scope

  • The volume mount for db data (db-data:/var/lib/mysql) already exists on master, so that part of Improve the Docker-Compose #1933 looks already resolved — no change needed there.
  • I also attempted the JRE-only multi-stage Dockerfile requested in Optimized Docker image (modified Dockerfile) #1919, but found the Maven build itself needs a live database during docker build: both the jOOQ codegen and the Flyway migrations run in the generate-sources phase against a real MariaDB connection (jOOQ generates Java classes from the live schema). A plain multi-stage Dockerfile's build stage has no access to other compose services, so that approach doesn't actually work — it needs something like a compose-orchestrated build step or a prebuilt WAR instead. Rather than submit a Dockerfile change that looks right but breaks in practice, I've scoped this PR to the compose networking fix, which I could fully verify.

Addresses part of steve-community#1933.

- Removed `ports: 3306:3306` on the db service. The app container never
  needed it on the host network — it already reaches the database as
  "mariadb" (now via an explicit network alias instead of the legacy
  `links:`). Exposing the database port to the host was unnecessary
  surface area.
- Added an explicit `steve-net` bridge network for db<->app traffic,
  replacing the implicit default network and legacy `links:` mapping.

Tested end to end with `docker compose up --build`: app builds, connects
to the db over steve-net, starts ("Started SteveApplication..."), and is
reachable on host port 8180 (302, as expected pre-login) -- while the db
is no longer reachable from the host at all (confirmed via `docker compose
ps`, no host port binding on the db service).

Not included in this PR: the volume mount for db data already exists on
master (`db-data:/var/lib/mysql`), so that part of steve-community#1933 looks already
resolved and needed no change. I also attempted the JRE-only multi-stage
Dockerfile from steve-community#1919, but the Maven build (jOOQ codegen + Flyway
migrations both run in the generate-sources phase against a live
database) needs a reachable MariaDB *during* `docker build`, which a
plain multi-stage Dockerfile can't provide -- that needs a different
approach (e.g. a compose-orchestrated build step, or a prebuilt WAR), so
I've scoped this PR to the compose networking fix only rather than
submit something that doesn't actually solve steve-community#1919.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Harden Docker Compose database networking

✨ Enhancement ⚙️ Configuration changes 🕐 Less than 10 minutes

Grey Divider

AI Description

• Removes MariaDB's host port binding to reduce unnecessary database exposure.
• Routes app-to-database traffic through an explicit bridge network and stable mariadb alias.
Diagram

graph TD
  HOST["Host client"] -->|"8180 / 8443"| APP["App container"] -->|"joins"| NET["steve-net"] -->|"mariadb:3306"| DB[("MariaDB")]
  HOST -. "no host port" .-> DB
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use the Compose service name
  • ➕ Eliminates the explicit mariadb network alias.
  • ➕ Uses Compose's built-in DNS name db directly.
  • ➖ Requires changing the existing Dockerfile connection hostname.
  • ➖ Broadens the scope and risks breaking other assumptions around the mariadb hostname.
2. Keep the implicit default network
  • ➕ Requires fewer Compose declarations.
  • ➕ Still allows service-to-service connectivity without exposing MariaDB.
  • ➖ Makes network isolation and intent less explicit.
  • ➖ Would still require an alias or application hostname change after removing links:.

Recommendation: Keep the PR's explicit bridge network and mariadb alias. It removes legacy links:, preserves the application's established database hostname, clearly documents service isolation, and avoids unnecessary Dockerfile changes.

Files changed (1) +15 / -6

Other (1) +15 / -6
docker-compose.ymlIsolate MariaDB on an explicit Compose network +15/-6

Isolate MariaDB on an explicit Compose network

• Removes MariaDB's host port publication and replaces legacy 'links:' connectivity with the 'steve-net' bridge network. Adds a 'mariadb' network alias so the application retains its existing database hostname while only application ports remain host-accessible.

docker-compose.yml

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can route each action level your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

ugurcihan added a commit to ugurcihan/portfolio that referenced this pull request Sep 28, 2026
- Rewrite About (EN/TR): drop "all of my conviction goes to KuExpo",
  state real launches (KuExpo on App Store + Google Play, LifeCheck on
  App Store) and openness to joining a team; fix LifeCheck description
- Preview modal renders multiple outbound links; add App Store / Google
  Play links to KuExpo and LifeCheck, repo link to Gridspark
- Group projects (Products / Engineering & Open Source / Web & Design /
  Ventures & Concepts), card titles to h4 under group h3s
- New Open Source card linking mobilityhouse/ocpp#776 and
  steve-community/steve#2143
- LinkedIn in contact, footer and JSON-LD sameAs; footer profile links
- Remove stale public drafts (variant-a..d, style-a..d, script-a) and
  the old resume PDF
- Shorten hero scroll (325vh -> 200vh desktop, 250vh -> 170vh mobile)
- Security headers, branded 404, sitemap lastmod
- Versioned hero/background assets with immutable caching; other assets
  1 day + stale-while-revalidate instead of 5 minutes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant