PortGate

Blueprints · Docker & Databases

Production 20 min · Docker

Docker Engine daemon hardening and UFW-safe publishes

Sets live restore, blocks new privileges by default, turns off default-bridge snooping, rotates JSON logs, and shows the 127.0.0.1 publish form that keeps Docker from opening a port past UFW.

Live config

Baked-in protections

Step 1 · json

daemon.json

/etc/docker/daemon.json

icc false affects the default bridge. Compose networks that you declare still connect the services you list.

{
  "live-restore": true,
  "no-new-privileges": true,
  "icc": false,
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

Step 2 · bash

Apply the daemon and check a publish

/root/portgate-blueprints/docker-daemon.sh

Restarting Docker drops containers when live-restore was not already on. Apply this during a maintenance window.

#!/bin/sh
set -eu
mkdir -p /etc/docker
python3 - <<'PY'
import json
from pathlib import Path
path = Path("/etc/docker/daemon.json")
wanted = {
    "live-restore": True,
    "no-new-privileges": True,
    "icc": False,
    "log-driver": "json-file",
    "log-opts": {"max-size": "10m", "max-file": "3"},
}
current = {}
if path.exists():
    current = json.loads(path.read_text() or "{}")
current.update(wanted)
path.write_text(json.dumps(current, indent=2) + "\n")
PY
systemctl restart docker
echo "Publish app ports as 127.0.0.1:8080:8080 so UFW is not bypassed."