Shipping an application inside an OCI image solves dependency drift on a laptop, yet default dockerd installations on Linux servers ship with operational footguns that routinely cause production security incidents and midnight disk-full outages. Out of the box, publishing a database port with -p 5432:5432 silently bypasses Ubuntu's ufw firewall and exposes PostgreSQL to the entire public internet; unrotated container stdout JSON logs fill /var/lib/docker/containers until the root filesystem goes read-only; restarting the Docker daemon kills every live container unless live-restore is active; and uncapped containers allow a single memory leak or fork bomb to take down the host kernel.
Production Docker container hosting—whether you run a hardened Linux VPS with Docker Compose or deploy onto a managed container plane—comes down to locking down daemon defaults, binding published ports strictly to loopback or internal bridges, enforcing cgroup v2 memory and PID limits, running non-root multi-stage images, and streaming encrypted volume backups off-host.
0.0.0.0 Firewall Trap: Why ports: - "5432:5432" Bypasses ufwThe single most widespread vulnerability on self-managed Docker hosts happens when an engineer runs ufw default deny incoming && ufw allow 22,80,443/tcp, assumes port 5432 is blocked externally, and writes ports: ["5432:5432"] in compose.yaml. Within minutes, internet scanners connect directly to PostgreSQL or Redis on <public-ip>:5432.
Why did ufw fail to stop the packet? Inspecting Linux netfilter packet flow explains the exact mechanism:
ufw installs its host filtering rules inside the netfilter INPUT chain, which processes packets destined for local host sockets.-p 5432:5432 (equivalent to 0.0.0.0:5432->container_ip:5432), dockerd programs a DNAT rule inside the nat PREROUTING chain—which executes before routing decisions!DNAT rewrites the destination IP from the host's public IP to the container's 172.18.0.x bridge IP, the Linux kernel classifies the packet as routed traffic traversing the FORWARD chain, completely skipping ufw's INPUT rules!Three rules eliminate this class of exposure permanently:
ports: for internal backing services: Containers sharing a user-defined Compose network (internal_backend) resolve each other by service name (db:5432, redis:6379) over virtual Ethernet bridges with zero ports: block needed.127.0.0.1: Always write "127.0.0.1:5432:5432" or "127.0.0.1:8080:8080"—never "5432:5432" or "8080:8080"—when a host tool or reverse proxy connects over loopback.ss -tulpn plus nft list table ip nat locally)./etc/docker/daemon.json (live-restore + Log Rotation)Before starting a single workload on a self-managed Ubuntu 24.04 or Debian 12 VPS, configure /etc/docker/daemon.json to address four production failure modes:
max-size / max-file): Docker's default json-file logging driver retains every byte written to stdout/stderr forever. Capping each container at 5 × 20m (100 MB ceiling) guarantees chatty debug logs never exhaust persistent disk space."live-restore": true): Decouples running containerd-shim processes from the dockerd management daemon so apt upgrade docker-ce restarts dockerd without dropping active customer HTTP connections."no-new-privileges": true): Sets the Linux kernel PR_SET_NO_NEW_PRIVS bit by default across containers, blocking setuid/setgid binaries inside compromised images from escalating to UID 0."icc": false) & Kernel Forwarding ("userland-proxy": false): Forces explicit user-defined Compose networks per stack and uses pure kernel netfilter Hairpin NAT instead of spawning a user-space docker-proxy process per port.{
"log-driver": "json-file",
"log-opts": {
"max-size": "20m",
"max-file": "5",
"compress": "true"
},
"live-restore": true,
"no-new-privileges": true,
"icc": false,
"userland-proxy": false,
"default-address-pools": [
{
"base": "172.24.0.0/14",
"size": 24
}
]
}
Notice default-address-pools: pinning Docker's automatic bridge allocations inside 172.24.0.0/14 prevents docker compose up from grabbing 172.17.0.0/16 or 10.x.0.0/16 subnets that collide with your corporate or cross-cloud WireGuard virtual networks.
compose.yaml: cgroup v2 Memory, pids_limit, and HealthchecksA Compose file without resource constraints gives every container unlimited access to host RAM and kernel PID slots. Production compose.yaml manifests enforce deterministic startup ordering (condition: service_healthy), hard cgroup v2 mem_limit and pids_limit ceilings, read-only container root filesystems (read_only: true with volatile tmpfs for /tmp), dropped Linux capabilities (cap_drop: [ALL]), and loopback-only upstream port bindings:
# /srv/stacks/billing-api/compose.yaml
name: billing-stack
services:
api:
image: registry.example.com/billing-api:v3.2.0
restart: unless-stopped
init: true
user: "10001:10001"
read_only: true
tmpfs:
- /tmp:size=64m,noexec,nosuid,nodev
security_opt:
- no-new-privileges:true
cap_drop:
- ALL
mem_limit: 1024m
memswap_limit: 1024m
cpus: 1.50
pids_limit: 256
ports:
# Bound strictly to loopback; host Caddy terminates public TLS 443
- "127.0.0.1:8080:8080"
environment:
NODE_ENV: production
DB_HOST: postgres
DB_PORT: "5432"
DB_NAME: billing
DB_USER: billing_app
DB_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_password
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD", "/usr/local/bin/healthcheck", "http://127.0.0.1:8080/readyz"]
interval: 10s
timeout: 3s
retries: 3
start_period: 15s
networks:
- backend_internal
postgres:
image: postgres:17.2-bookworm
restart: unless-stopped
shm_size: 256m
mem_limit: 2048m
memswap_limit: 2048m
pids_limit: 256
security_opt:
- no-new-privileges:true
# ZERO "ports:" mapping — completely unreachable from eth0 or localhost outside backend_internal!
environment:
POSTGRES_DB: billing
POSTGRES_USER: billing_app
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_password
volumes:
- pg_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U billing_app -d billing"]
interval: 5s
timeout: 3s
retries: 5
networks:
- backend_internal
secrets:
db_password:
file: /run/secrets/billing_db_password
volumes:
pg_data:
networks:
backend_internal:
driver: bridge
internal: true
Setting memswap_limit equal to mem_limit disables container swap thrashing: if a leaking worker hits 1024 MB, the kernel OOM-kills and restarts only that single container in milliseconds instead of driving the entire host into multi-minute disk I/O paralysis. Meanwhile, internal: true on backend_internal blocks containers on that bridge from initiating arbitrary outbound internet connections—neutralizing reverse-shell callbacks if an application dependency is compromised (swap to standard bridge only on services that legitimately call external HTTPS APIs).
Dockerfile HygieneRunning application processes as root (UID 0) inside a container means any kernel namespace or volume-mount escape immediately yields root on the hypervisor guest. Build artifacts in an isolated compiler stage and copy only the static binary or pruned runtime bundle into a minimal non-root final image (UID 10001):
# syntax=docker/dockerfile:1.7
FROM golang:1.24-bookworm AS builder
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -trimpath -ldflags="-s -w" -o /out/billing-api ./cmd/server && \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -trimpath -ldflags="-s -w" -o /out/healthcheck ./cmd/healthcheck
FROM debian:bookworm-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates tzdata \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd --gid 10001 appgroup \
&& useradd --uid 10001 --gid 10001 --no-create-home --shell /usr/sbin/nologin appuser
COPY --from=builder --chown=0:0 --chmod=0555 /out/billing-api /usr/local/bin/billing-api
COPY --from=builder --chown=0:0 --chmod=0555 /out/healthcheck /usr/local/bin/healthcheck
USER 10001:10001
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/billing-api"]
Notice --chown=0:0 --chmod=0555: the binary is owned by root and executable—never writable—by UID 10001, preventing an RCE vulnerability from overwriting its own executable on disk even if read_only: true is omitted.
/cloud-storageCopying raw /var/lib/docker/volumes/pg_data files while PostgreSQL or SQLite is actively writing pages produces corrupted backups with torn 8 KiB pages. Always trigger logical consistent snapshots (pg_dump --format=custom or sqlite3 .backup) plus restic / AES-256 encrypted archives streamed off-host to Managed Cloud Storage hosted via Microsoft Azure (5 GiB free sandbox, 250 GiB at $9/mo, dual-layer AES-256-GCM + Azure storage encryption):
#!/usr/bin/env bash
# /etc/cron.daily/backup-billing-stack — Consistent logical DB dump + off-host upload
set -euo pipefail
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
OUT="/tmp/billing-pg-${STAMP}.dump.zst"
trap 'rm -f "$OUT"' EXIT
docker exec billing-stack-postgres-1 \
pg_dump -U billing_app -d billing --format=custom --compress=0 \
| zstd -T0 -9 > "$OUT"
# Upload encrypted backup artifact to off-host Managed Cloud Storage (/cloud-storage)
az storage blob upload \
--connection-string "${AZURE_MANAGED_STORAGE_CONN}" \
--container-name "prod-docker-backups" \
--name "billing/pg-${STAMP}.dump.zst" \
--file "$OUT" \
--overwrite false
Servers Are Up supports four distinct ways to run containers, depending on whether you want turnkey single-app hosting, managed multi-container execution without maintaining a host OS, Git-driven builds, or full root KVM control:
| Servers Are Up Option | Compute & Storage Allocation | Monthly Price | Host / Socket Boundary & Ideal Use Case |
|---|---|---|---|
Managed Docker (Starter / Standard / Pro) |
2 vCPU / 2 GB / 50 GB ($6), 4 vCPU / 4 GB / 100 GB ($10), 8 vCPU / 8 GB / 200 GB ($18) |
$6 / $10 / $18/mo |
Up to 10 / 25 / 64 containers on a managed execution plane (customerDockerSocketAccess: false prevents container root escapes via /var/run/docker.sock) |
| Custom GitHub App | 2 vCPU, 4 GB RAM, 50 GB persistent storage | $10/mo |
Builds and deploys 1 custom app directly from your GitHub repository (Dockerfile or Railpack) with automatic TLS |
| Single App Containers (Instant Apps) | 2–8 vCPU, 2–16 GB RAM, 50–320 GB persistent storage | $8 / $13 / $24 / $46/mo |
Turnkey pre-configured open-source apps (Ghost, n8n, Dify, Strapi, Forgejo, Grafana, Uptime Kuma) |
| Linux Cloud VPS | 2–16 vCPU, 2–48 GB RAM, 50–960 GB persistent storage | $6–$56/mo |
Full root KVM server for custom compose.yaml stacks + 69 free 1-click app installers right in the server Apps tab |
When your stack outgrows single-host Docker and requires multi-node pod failover and RollingUpdate quorum guarantees, compare our K3s cloud cluster architecture ($18, $42, and $140/mo at /containers).
customerDockerSocketAccess: false?Mounting /var/run/docker.sock inside a container or untrusted CI/CD agent grants unrestricted root equivalence over the host daemon (docker run --privileged -v /:/host). Setting customerDockerSocketAccess: false on Managed Docker plans ($6/$10/$18/mo) lets you deploy OCI images, configure environment secrets, attach persistent volumes, and view logs safely through our control plane and /api/v1 API without exposing raw daemon socket privilege-escalation paths. When you genuinely need raw /var/run/docker.sock (for example, Testcontainers or custom BuildKit runners), use a dedicated Linux Cloud VPS ($6+/mo) where you own an isolated KVM kernel.
mem_limit values?Keep the sum of steady-state container working sets at 65–75% of host RAM, reserving at least 750 MB–1.5 GB for the Linux kernel, containerd/dockerd, systemd-journald, TLS reverse proxies, and Linux page cache. During rolling docker compose up -d image pulls and layer extractions, transient filesystem cache and decompression buffers spike noticeably.
Yes. Every rented Linux Cloud VPS ($6/mo Starter through $56/mo Enterprise) includes free access to 69 one-click self-hosted app installers from the server's Apps tab—or your own compose.yaml stacks—limited only by the vCPU, RAM, and persistent storage of the server you chose. Standalone Instant App plans ($8–$46/mo at /self-hosted) are for teams who prefer a dedicated single-app container managed for them without operating a Linux server.
init: true in compose.yaml for Node.js and Python containers?When Node.js, Python, or a shell script runs directly as PID 1 inside a container, it typically lacks handlers for SIGTERM forwarding and fails to reap orphaned zombie child processes (<defunct>), eventually exhausting your pids_limit. Setting init: true injects tini as PID 1 to forward signals cleanly and reap zombie subprocesses automatically.
Explore With AI & Cite This Page
Open a grounded prompt in your AI assistant or copy a clean Markdown, HTML, or APA reference link.
Validate protocols and subnets directly in your browser or continue reading related architecture notes.
Free Docker Compose Security Linter & Audit
Linux, Windows & Game Server Hardening Checklist
CVE Vulnerability & CISA KEV Banner Advisor
Docker Hosting Providers Compared (2026): Dedicated KVM Container Hosts vs. Multi-Tenant PaaS and Linux VPS
An engineering comparison of Docker hosting architectures in 2026: per-customer KVM Managed Docker ($6/$10/$18), Custom GitHub Apps ($10), Single App Containers ($8-$46), Linux VPS ($6+), and metered PaaS.
High-Concurrency CMS Hosting: PHP-FPM Memory Math, Nginx Microcaching, Headless Node, and Object Offload
Scale Ghost, WordPress, Strapi, Directus, and Payload CMS: PHP-FPM worker sizing, Nginx stale-while-revalidate microcaching, Redis, and Azure media offload.
Self-Hosting GitLab CE Without OOM Kills: Omnibus Memory Tuning, Isolated CI Runners, and Object Offload
Run GitLab CE reliably on Linux KVM: /etc/gitlab/gitlab.rb Puma and Sidekiq tuning, isolated Docker CI runner VMs, Azure object offload, and Gitea tradeoffs.
How to Install Docker on Ubuntu 24.04 LTS: Official APT Keyring, daemon.json Tuning & Rootless Security
Install official Docker Engine (docker-ce) and Compose v2 on Ubuntu 24.04 LTS using DEB822 APT keyrings, prevent disk-full outages with daemon.json log rotation, and understand docker group root equivalence vs Rootless Docker.