Concept
The image
How the image arises from the standalone output, what is in it and how GitHub Actions builds and publishes it.
Structure
Everything about Docker lies under docker/. The build context is the root
of the project, so every call names the Dockerfile with -f. The Dockerfile
builds in two stages:
| Stage | Base | What happens |
|---|---|---|
build | node:22 | npm ci, npm run build |
runtime | node:22-slim | takes from the standalone output only what the server needs |
What does not belong into the build context is listed in
docker/Dockerfile.dockerignore: node_modules, .next, .git, .data*,
test results, .env, .env.local, docker/.env and .claude. BuildKit
reads a file with the name of the Dockerfile and the extension
.dockerignore instead of a .dockerignore in the root.
The standalone output
next.config.mjs sets:
output: "standalone",
outputFileTracingExcludes: { "*": ["node_modules/@img/**", "node_modules/sharp/**"] },
serverExternalPackages: ["better-sqlite3"],
images: { unoptimized: true },
output: "standalone"bundles nearly everything into the server bundles under.next. Only a few modules stay, among them Next.js, React andbetter-sqlite3.sharpbelongs to Next.js but is never needed, because the image optimizer is off. It stays out.better-sqlite3is a native module. It is not bundled and is installed in the build stage for the platform of the image. Anode_modulesfrom your computer must therefore never go into the image.
The runtime stage copies server.js, package.json, node_modules and
.next from .next/standalone, plus .next/static, public/ and docs/.
The standalone output does not copy .next/static and public/; without
them scripts, styles and images would be missing. docs/ is read at
runtime by /docs and /docs-image.
In the container
| What | Value |
|---|---|
| user | node, UID 1000 |
| root directory | HENNIOKF_ROOT=/henniokf, mounted, must belong to UID 1000 |
| port | PORT=3370, EXPOSE 3370 |
| address | HOSTNAME=0.0.0.0 |
| start | node server.js |
| version | HENNIOKF_COMMIT and HENNIOKF_BUILT_AT from the build arguments COMMIT and BUILT_AT |
Docker sets HOSTNAME to the id of the container. Without
HOSTNAME=0.0.0.0 the server would listen on one address only, and Traefik
would not reach it.
The build arguments stand after all expensive steps, so a new commit does not invalidate the cache before them.
Building
docker/build.sh -t henniokf
docker/build.sh calls docker buildx build -f docker/Dockerfile from the
root, gives the image commit and build time and passes every further
argument on. If the working tree has uncommitted changes, the commit carries
the suffix +dirty. For a VPS with amd64 from a computer with Apple
silicon:
docker/build.sh --platform linux/amd64 -t ghcr.io/arpablo/henniokf:latest
Without the script it works too, but the image does not know its version:
docker build -f docker/Dockerfile -t henniokf .
The script checks nothing. Before a build for production run
npm run check and npm run test:e2e.
Built on GitHub
The workflow "Image" (.github/workflows/image.yml) runs when "Check" was
green on main, or by hand. In this order:
- Determine the version: short commit, build time, date.
- Log in to
ghcr.iowith the built-inGITHUB_TOKEN. No token of its own is needed. - Build and load, not publish, for
linux/amd64, with the cache of GitHub Actions. - Start and answer: start the container with an empty root directory
and ask
GET /sign-inup to 60 times at two-second intervals. Only on 200 it goes on. Then the step checks that/answers 200 without signing in, because reading is public, thatbetter-sqlite3loads in the container, which the backup needs, and thatdocs/index.mdlies in it. - Publish with three tags:
| Tag | Meaning |
|---|---|
ghcr.io/arpablo/henniokf:latest | the newest green state of main |
ghcr.io/arpablo/henniokf:<commit> | a fixed state, for going back |
ghcr.io/arpablo/henniokf:<date> | the last state of a day |
If the start test fails, nothing is published, and the VPS keeps the
current image. In the template repository arpablo/HenniTemplateRepo step 5
is skipped by a condition; HenniOKF has another name and publishes.
The registry
A newly published package of a personal account is private. The label
org.opencontainers.image.source links it to the repository. Only who logs
in with a token (classic) with read:packages may pull it. After the
open-source release the package is meant to become public; then that login
falls away. Mind that, after the documentation of GitHub, a public package
cannot be made private again.
What is in the image and what not
| In the image | Not in the image |
|---|---|
the built application under .next | the source as such, the tests, context/, .github/ |
| the few modules Next.js does not bundle | the rest of node_modules, also sharp |
public/ and docs/ | .env.local and every secret |
| Node 22, commit and build time | the data of the instance; it lies in the mounted root directory |
An image can be unpacked completely. Whoever may pull it can read what is in it.
Next: Compose locally.