Remediation Guide · DKR001–DKR006 · 0-Upload Linter

How to Fix Docker Compose Exposed Ports (0.0.0.0:5432) & docker.sock Mounts

Docker bypasses UFW by default whenever you write "5432:5432" or "6379:6379" without a 127.0.0.1 prefix. Fix DKR001–DKR006 cleanly and verify your docker-compose.yml locally below with 0 bytes uploaded.

Lint docker-compose.yml (0 Upload) Pro Solo $29 → Pro Team (10 seats) — $49 Free .vsix (156 KB)

100% client-side YAML AST engine · 0 bytes sent · One-time Polar.sh license (no subscription) unlocks all 72 rules + CI SARIF 2.1.0.

Vulnerable vs. Hardened docker-compose.yml (Before & After)

This side-by-side diff eliminates public database exposure (DKR001), container breakout via privileged: true (DKR002) and docker.sock (DKR003), unpinned :latest tags (DKR004), network_mode: host (DKR005), and cap_add: SYS_ADMIN (DKR006).

VULNERABLE — docker-compose.yml 6 Findings (DKR001–DKR006)
services:
  postgres:
    image: postgres:latest
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: demo_plaintext_db_pass_912
  worker:
    image: myorg/worker:latest
    privileged: true
    network_mode: host
    cap_add:
      - SYS_ADMIN
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
HARDENED — docker-compose.yml 0 Critical Findings · Loopback + Least Privilege
services:
  postgres:
    image: postgres:16.6-alpine
    restart: unless-stopped
    ports:
      - "127.0.0.1:5432:5432"
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?required}
    security_opt: ["no-new-privileges:true"]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 15s
  worker:
    image: myorg/worker:1.4.2
    user: "1000:1000"
    restart: unless-stopped
    read_only: true
    security_opt: ["no-new-privileges:true"]
    cap_drop: ["ALL"]
    mem_limit: 512m

Lint Your docker-compose.yml Locally (All 18 Docker Rules)

100% in-browser · 0 bytes sent · < 10 ms

Paste any docker-compose.yml or compose.yaml below to audit exposed ports, docker.sock mounts, privilege escalation, secrets, and resource limits locally in your browser.

1-Click Quick Fixes in VS Code & Cursor + CI SARIF 2.1.0 Unlock StackGuard Pro once via Polar.sh (zero subscription) to enforce all 72 rules across Docker Compose, MCP, n8n, and Caddy/Traefik in every pull request.

Exact Remediation Reference: Rules DKR001–DKR006

Rule ID Severity Vulnerability & CWE Exact Fix
DKR001 HIGH
Database, cache, or admin port exposed on 0.0.0.0
CWE-668SOC 2 CC6.6DORA Art. 9(3)
Prefix host ports with 127.0.0.1:5432:5432 or drop ports: entirely so services only talk over an internal Docker bridge network.
DKR002 CRITICAL
Privileged container enabled (privileged: true)
CWE-250SOC 2 CC6.3ISO A.8.2
Remove privileged: true, set cap_drop: ["ALL"], and enable security_opt: ["no-new-privileges:true"].
DKR003 CRITICAL
Docker daemon socket (/var/run/docker.sock) mounted
CWE-269SOC 2 CC6.3DORA Art. 9(4)
Remove direct docker.sock bind mounts from app/proxy containers; route read-only container discovery through tecnativa/docker-socket-proxy.
DKR004 MEDIUM
Unpinned container image tag (:latest or missing tag)
CWE-829SOC 2 CC8.1ISO A.8.8
Pin explicit immutable versions or SHA-256 digests (e.g. postgres:16.6-alpine) so deployments are reproducible and auditable.
DKR005 HIGH
Host network mode enabled (network_mode: host)
CWE-668SOC 2 CC6.6ISO A.8.20
Remove network_mode: host and isolate services on a user-defined Compose bridge network with explicit loopback or reverse-proxy ingress.
DKR006 HIGH
Dangerous Linux capability added in cap_add
CWE-250SOC 2 CC6.3ISO A.8.2
Drop ALL, SYS_ADMIN, SYS_PTRACE, and NET_ADMIN; grant only minimal non-root capabilities such as NET_BIND_SERVICE if required.

Frequently Asked Questions

Why does ports: "5432:5432" in docker-compose.yml bypass UFW firewall rules on Linux?

Docker injects DNAT iptables rules ahead of UFW's user input chains, exposing any 0.0.0.0 mapped port directly to the internet unless bound to 127.0.0.1:5432:5432 or kept internal without ports:.

Why is mounting /var/run/docker.sock (DKR003) equivalent to root on the host?

Any container able to call the Docker API can start a privileged container mounting /:/host, gaining immediate host root shell access.

Does the embedded Docker Compose linter upload my YAML file?

No. StackGuard runs its 18-rule YAML AST analyzer 100% locally in your browser with zero outbound network requests.

How can I block DKR001–DKR018 automatically in CI/CD?

Run stackguard-cli in GitHub Actions with SARIF 2.1.0 output and install the StackGuard .vsix extension in VS Code, Cursor, or Windsurf for 1-click Quick Fixes.

Oriancy Local Security Quartet

4 Zero-Upload Scanners · 1 One-Time Bundle
DevSecOps Quartet Bundle — All 4 local CLIs & auditor packs on one-time Polar licenses · oriancy.com