zurück zur Tech-Wiki
Tech-Wiki/Infrastruktur
D

Docker

Container-Plattform für reproduzierbare Build-/Deploy-Pipelines.

·Docker Inc.·Apache-2.0

Übersicht

Was ist es?

Docker containerisiert Anwendungen — reproduzierbare Builds, isolierte Runtimes, identische Umgebungen von Dev bis Prod. Standard für Deploy-Pipelines (auch hier: Frontend baut auf Coolify via frontend/Dockerfile).

Quickstart

brew install --cask docker
docker --version
docker run hello-world

Minimaler Next.js-Dockerfile:

FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile

FROM deps AS build
COPY . .
RUN pnpm build

FROM node:20-alpine AS run
COPY --from=build /app/.next/standalone ./
CMD ["node", "server.js"]

Typische Patterns

  • Multi-Stage Builds — Build-Tools im ersten Stage, schlankes Runtime-Image am Ende.
  • .dockerignore mit node_modules, .next, .git — Build-Context klein halten.
  • Layer-Caching: erst package.json kopieren + install, dann Source — Re-Build nur bei Dep-Änderung.
  • docker compose für lokale Multi-Service-Stacks (Supabase self-hosted nutzt das).
  • Non-Root-User im Final-Stage: USER node für Security.

Gotchas / Was oft schiefgeht

  • COPY . . ohne .dockerignore → ganzes Repo (inkl. node_modules, .git) im Build-Context, schlechte Performance.
  • Apple-Silicon vs Linux/amd64: Builds laufen lokal, brechen auf Server. --platform=linux/amd64 setzen.
  • Layer-Order falsch → Cache wird invalidiert. Erst Deps, dann Source.
  • Secrets in ENV landen im Image — --secret-Mount nutzen oder Build-Args, die nicht in Final-Layer landen.
  • latest-Tag in Production = Roulette. Konkrete Versions-Tags / Digests.

Wann nicht?

Statische Sites ohne Backend → Edge-Hosting (Vercel/Cloudflare Pages) ohne Docker-Overhead. Native-Apps offensichtlich nicht.

Eingesetzt in