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
- Previewly parses your repo-root config (
previewly.toml/ yaml / yml) and honours an explicitdockerfilepath first. - If no config-supplied Dockerfile was requested, Previewly probes the server default (
Dockerfileunless your operator customised it) beneath the archived repository root—useful for teams migrating incrementally. - If neither artefact exists, Previewly derives a Dockerfile from heuristic stack detection (
runtimehints, lockfiles,startup_*fields) prior to invoking Fly.
Layouts and monorepos
- Colocate Dockerfile context with Dockerfile content so
COPYbehaves 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
.dockerignorebeside 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.0on the Previewly-internal port surfaced by Fly (Previewly mergesPORTbeforehand). EXPOSEaligns with whichever port Previewly configures in its generated Fly app manifest (internal_port/ server default).
Stack notes
| Stack | Reminder |
|---|---|
| Next.js standalone | Multi-stage Dockerfile copies traced output from .next/standalone so you do not reinstall dev tooling in the runtime slice. |
| Python workers | Honour $PORT with Gunicorn, Uvicorn, or waitress flags so Fly health checks succeed promptly. |
| Rust / JVM / statically linked Go | Binary targets should read Fly's injected environment for host binding—Previewly forwards the upstream PORT contract unchanged. |
| Static assets | Pair nginx/Caddy—or rely on Previewly's generated static shim—listening on whichever internal port aligns with Previewly routing. |