Back to blog
Deploy7 min read

Do you really need a Dockerfile? Framework presets vs. custom containers

Dockerfiles are a great tool. For an app that's just Next.js or Django, though, they're often one more file to maintain.

A four-person team had a 120-line Dockerfile for their Next.js app. None of the current team had written it; it was copied from a previous project. The base image hadn't been updated in two years, builds took eight minutes, and once, when Node needed a newer version, half a day went into finding the line that pinned it.

When we deployed the same project with no Dockerfile, using only the Next.js preset, builds dropped under three minutes and those 120 lines were deleted from the repo.

That doesn't make Docker bad. For plenty of problems it's the best answer. The question is which problem you have.

What does a preset actually do?

A preset means the platform knows your framework and how to build it. For a Next.js app, the platform detects the package manager (npm, pnpm or yarn) from package.json and the lockfile, installs dependencies with a cache, runs build, and starts the output with settings suited to that framework.

In practice that's the same work you'd write in a good Dockerfile, except someone else maintains it: the base image gets updated, OS security patches get applied, and the dependency cache is kept between builds.

CriterionFramework presetCustom Dockerfile
Setup timeMinutes; connect the repoAn hour to a day, depending on experience
Base image updates and security patchesHandled by the platformYours; if forgotten, they don't happen
Arbitrary system packages (ffmpeg, etc.)LimitedAnything
Identical runs locally and on other serversDepends on the platformYes; the image is the same everywhere
Build cacheAutomaticYou have to order the layers correctly
Good forCommon web apps and APIsSpecial runtimes, native dependencies, running in several places

Four questions to decide

Ask these in order. The first answer that leads to a Dockerfile settles it; if none do, a preset is the better choice.

Four questions for choosing between a framework preset and a Dockerfile

System packages are the most common real reason. An app that transcodes video with ffmpeg, renders PDFs with headless Chromium, or processes geodata with GDAL needs things npm install won't give it.

A specific runtime is a valid reason too: an old Python version an old library depends on, or a language the platform has no preset for.

Running in several places matters when the same image has to run identically on a client's server, in an isolated environment, or on teammates' laptops.

What's not on the list: "because everyone uses Docker" and "we might need it later". If you need it later, writing a Dockerfile for a standard app takes an hour. Maintaining an unused Dockerfile is a cost you pay every month.

If you need a Dockerfile, write it like this

Say your Node.js app needs ffmpeg to generate video thumbnails. A minimal, maintainable Dockerfile looks like this:

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

FROM node:22-slim AS build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN corepack enable && pnpm build

FROM node:22-slim AS run
# The only reason this file exists:
RUN apt-get update \
  && apt-get install -y --no-install-recommends ffmpeg \
  && rm -rf /var/lib/apt/lists/*
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
COPY --from=build /app/public ./public
USER node
EXPOSE 3000
CMD ["node", "server.js"]

A few things in this file that copied Dockerfiles usually miss:

  • Multiple stages. Build tools and the full node_modules don't end up in the final image. A smaller image ships faster and has less attack surface.
  • Copying the lockfile before the rest of the code. As long as dependencies haven't changed, the install layer comes from cache and builds are several times faster.
  • USER node. The app doesn't need to run as root, and if there's ever a vulnerability, this limits the damage.
  • A pinned base image (node:22-slim) instead of latest, so today's build and next month's are the same.

You also need a .dockerignore, or your local node_modules and .git folder end up in the build context:

.dockerignore
node_modules
.next
.git
.env*
!.env.example
npm-debug.log*

The middle path: preset now, Dockerfile when needed

Our suggestion for most small teams: start with the preset. On the day the first native dependency enters the project, add a Dockerfile. On Parslinks, if there's a Dockerfile at the project root (or in the folder you set as root), it's used; if not, the framework preset is. Everything else, from branch previews to domains to rolling back, works the same either way.

So today's decision isn't final. If you remove the Dockerfile one day, the app simply builds with the preset again.

Frequently asked questions

Join the discussion

No comments yet. Be the first to share your thoughts.