Dockerfile Generator
项目参数 选择运行时后自动套用安全默认
高级构建 缓存、标签与构建参数
缓存挂载需要 BuildKit;ARG 支持默认值,但敏感值不要写进 Dockerfile。
构建自检 改参数后即时重算
生成结果 可直接提交到仓库
构建命令与启动命令会按所选运行时套用默认值,生成后请按项目实际脚本调整。
How to Use
📖 What it does
A Dockerfile is rarely hard because of `FROM` or `COPY`. The difficulty sits in how layers, caches, runtime users and health probes fit together. Put compilers, source code and development dependencies into one stage and the image grows. Run as root and a compromised process has more room to move. Forget a `.dockerignore` and local dependency folders, logs and `.env` files travel into the build context.
This generator turns those decisions into a small set of visible parameters: runtime, base image version, container port, build command, start command and runtime user. Node.js gets a dependency stage, a build stage and a runtime stage. Go gets a static build with a distroless runtime. PHP gets a Composer stage separate from the web server. The right column also produces a matching `.dockerignore` so caches and local secrets do not enter the image.
Nothing is sent to a Docker daemon. Every line is assembled in the browser. Use the result as a structurally correct starting point, then adjust it for the scripts, ports and directories your repository actually contains.
✨ Features
- Six runtime presets for Node.js, Python, Go, PHP, Java and static sites, each with a matching base image and start command.
- Multi-stage builds with optional BuildKit cache mounts, keeping dependency, build and runtime layers separate.
- Node package manager awareness: npm, pnpm and yarn switch lock files, install commands and production pruning.
- Runtime hardening: custom non-root user, health-check path and image name, with checks for root users and invalid ports.
- Image metadata: optional OCI title, description and license labels, plus named ARG build arguments.
- A matching `.dockerignore` that removes Git data, dependencies, build output, logs, `.env` files and editor folders.
🚀 How to use it
- Pick a runtime and confirm the base image tag, container port, build command and start command; switching runtimes applies safe defaults.
- In the advanced card, choose the Node package manager, health-check path and image name, then add ARG names if needed.
- Keep multi-stage, non-root, BuildKit cache and OCI labels enabled, then read the build self-check.
- Switch between the Dockerfile and `.dockerignore` tabs and verify `COPY` order, `USER` and `HEALTHCHECK`.
- Copy or download both files into the project root, run `docker build -t app .`, then confirm cache hits and the start command in the log.
⚠️ Before you rely on it
- Pin the base image: `node:latest` can change major versions on the next build; use a tag such as `20-alpine`.
- Never bake secrets into the image: keep `.env`, private keys and cloud credentials out of the `COPY . .` context and inject them at runtime.
- Non-root users need writable paths: after switching users, log, cache and upload folders may fail; create or `chown` them during the build.
- Health checks must be real: the Node, PHP, Java and static examples use `wget`; the Go distroless example calls `/app/server -healthcheck`, so the app must implement that flag.
- Keep dependency layers reusable: copy `package.json`, `requirements.txt` or `go.mod` before installing, then copy source last.
- Distroless images have no shell, so debug tools belong in the build stage; PHP needs writable `storage` and `cache` folders before switching to `www-data`.