Generate a multi-stage Dockerfile for Node, Python, Go, Rust, Java, PHP or a static site, with layer caching ordered correctly and a non-root user.
Node.js service · checked against this site's own Dockerfile checklist
No warnings and no notes.
Alpine uses musl rather than glibc. Most things work; native modules with prebuilt glibc binaries do not, and some workloads are measurably slower because musl's allocator behaves differently under threads. If a native dependency fails to install, this switch is the first thing to try turning off.
Every base image this writes is pinned to a version. A :latest tag pins nothing — whoever publishes the image can move it, so the same Dockerfile builds a different image next week.
# Generated as a starting point. Review it before building:
# a template cannot know what your application needs at run time.
FROM node:22-alpine AS deps
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN corepack enable && pnpm install --frozen-lockfile
FROM node:22-alpine AS build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm build
FROM node:22-alpine AS runtime
WORKDIR /app
ENV NODE_ENV=production
# The node images already ship a non-root `node` user.
USER node
COPY --from=build --chown=node:node /app/node_modules ./node_modules
COPY --from=build --chown=node:node /app/dist ./dist
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s --start-period=20s --retries=3 \
CMD node -e "fetch('http://127.0.0.1:3000/').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
CMD ["node", "dist/index.js"]Checked against this site's Dockerfile inspector: no warnings. A generator that produces files its own checklist complains about has a bug in one of the two.
This is a starting point, not a finished Dockerfile, and the first line of the output says so. A template cannot know what your application needs at run time — a native dependency, a database migration, a writable temp directory, a non-default entry point. It also assumes a conventional project layout: a build output in dist, a manifest in the root. Read it before building it.
Dockerfile Generator runs entirely on your device — nothing is uploaded.
You’re on the Free plan. Compare plans
Two decisions account for most of what makes a Dockerfile good, and both are structural rather than a matter of flags. The first is copying the dependency manifest and installing before copying the source, so a code change does not invalidate the install layer. Get the order wrong and every build reinstalls everything — the build still works, which is why the mistake survives.
The second is the multi-stage split. Build tools, compilers and development dependencies belong in a stage that is thrown away; the final image gets the built output and a runtime. For a Go or Rust binary that is the difference between an image of a few hundred megabytes and one of a few.
Every template runs as a non-root user, and that is harder than adding a `USER` line — a user that cannot bind its port or write where the program expects produces a container that starts and then fails. The nginx template uses an unprivileged image on port 8080 and the PHP template moves Apache's ports before dropping privileges, because both would otherwise break.
Base images are pinned to a specific version rather than `latest`, so a rebuild next month produces the same image. A `latest` tag means your build depends on whatever was published since, which is the kind of thing that breaks on a Friday.
No Docker command is run and the local Docker daemon is never contacted. This generates text; building and testing the image is yours to do, and the output is a starting point to review rather than something guaranteed to work in your project.
Because Docker caches each layer and invalidates everything after the first change. Copying only the manifest, installing, and then copying the source means editing a source file reuses the cached install. Copying everything first reinstalls on every build.
Everything the build needed and the runtime does not: compilers, headers, development dependencies, caches. For a compiled language the final image can be a base image plus one binary. It also shrinks the attack surface, since a shell and a package manager that are not in the image cannot be used.
Because the default is root, and a process that is compromised inside the container starts with root in that namespace. Running as a normal user is one line of defence that costs nothing — provided the port and the writable paths suit, which is why the templates adjust both.
Yes. `node:latest` means your build depends on whatever was published since the last one. Pinning a minor version gets security patches without a surprise major upgrade; pinning a digest is fully reproducible and needs a deliberate update.
No. No Docker command is run and the daemon is never contacted. The output is generated text to review and build yourself.