Custom Dockerfile

Reach for a Dockerfile when customization matters

Previewly can synthesize runnable images straight from manifests such as package.json or go.mod. When generated defaults miss a build stage, distroless base layer, pinned CA bundle, GPU-less compiler flags, secrets baked through build-kit mounts, or anything else that needs explicit Docker authoring, declare dockerfile alongside your path.

How Previewly resolves an image today

  1. Previewly parses your repo-root config (previewly.toml / yaml / yml) and honours an explicit dockerfile path first.
  2. If no config-supplied Dockerfile was requested, Previewly probes the server default (Dockerfile unless your operator customised it) beneath the archived repository root—useful for teams migrating incrementally.
  3. If neither artefact exists, Previewly derives a Dockerfile from heuristic stack detection (runtime hints, lockfiles, startup_* fields) prior to invoking Fly.

Layouts and monorepos

  • Colocate Dockerfile context with Dockerfile content so COPY behaves identically locally and during preview builds.
  • Monorepo example: dockerfile = "apps/web/Dockerfile" while keeping install commands rooted to that subdirectory with multi-stage layering.
  • Optionally add .dockerignore beside the Dockerfile's build context root to trim node_modules artefacts, binaries, caches, secrets, etc.

Checklist authored containers must satisfy

  • Default process bootstraps the HTTP workload without prompting for interactive input.
  • Listening socket binds to 0.0.0.0 on the Previewly-internal port surfaced by Fly (Previewly merges PORT beforehand).
  • EXPOSE aligns with whichever port Previewly configures in its generated Fly app manifest (internal_port / server default).

Stack notes

StackReminder
Next.js standaloneMulti-stage Dockerfile copies traced output from .next/standalone so you do not reinstall dev tooling in the runtime slice.
Python workersHonour $PORT with Gunicorn, Uvicorn, or waitress flags so Fly health checks succeed promptly.
Rust / JVM / statically linked GoBinary targets should read Fly's injected environment for host binding—Previewly forwards the upstream PORT contract unchanged.
Static assetsPair nginx/Caddy—or rely on Previewly's generated static shim—listening on whichever internal port aligns with Previewly routing.

Back to Configuration · Troubleshooting