Image Slimming (pkg-slim)
pkg-slim is an opt-in FILES_IGNORE_GLOB profile manager shipped in Daemonless base images (base-core, base-exec, base-rcd, and base). It lets Containerfile builds skip documentation, development headers, static archives, and unused compiler binaries during pkg install without deleting files after the fact.
Because FreeBSD pkg skips matching paths at extraction time instead of relying on post-install rm -rf:
pkg check -s -astays clean with no missing-file errors.- Unneeded files are never written to an OCI layer and whiteout-deleted later.
- Shared runtime libraries (such as
libLLVM*.so*for PostgreSQL JIT and/usr/local/lib/gcc*/lib*.so*for GCC-linked ports) stay intact.
For example, enabling pkg-slim on ghcr.io/daemonless/postgres:18-pkg-latest reduces the image from ~2.63 GB to ~732 MB (-72%) while keeping pgvector and LLVM JIT working.
How It Works
Daemonless base images install /usr/local/etc/pkg.conf from pkg-slim:
Tier templates live in /usr/local/etc/pkg/daemonless-slim.available/. When you run pkg-slim enable, it symlinks the requested tiers into /usr/local/etc/pkg/daemonless-slim.d/, where pkg merges every FILES_IGNORE_GLOB array automatically. App-specific patterns are stored in /usr/local/etc/pkg/daemonless-slim.d/90-local.conf.
Base image default
base-core enables only the docs tier (10-docs.conf) by default. Headers, static archives, and compiler toolchains remain untouched in base images and multi-stage builder stages unless a Containerfile opts into dev or toolchain.
Tiers
| Tier | Drop-in | What it skips | What it keeps |
|---|---|---|---|
docs |
10-docs.conf |
/usr/local/share/doc/*, man pages (/usr/local/share/man/*, /usr/local/man/*, Perl man pages), /usr/local/share/examples/*, /usr/local/share/info/* |
Runtime data files under /usr/local/share/ |
dev |
20-dev.conf |
/usr/local/include/*, /usr/local/libdata/pkgconfig/*, static archives (/usr/local/lib/*.a, /usr/local/llvm*/lib/*.a) |
Shared libraries (*.so*) |
toolchain |
30-toolchain.conf |
LLVM/Clang binaries, headers, CMake/Clang/MLIR/LLDB libs, GCC compilers and internal passes, GNU binutils (ld, as, ar, nm, objdump, strip, etc.) |
Runtime shared libraries (libLLVM*.so*, /usr/local/lib/gcc*/lib*.so*) |
Commands
| Command | Behavior |
|---|---|
pkg-slim enable |
Replaces the enabled tier set. With no tier names, enables all three tiers (docs dev toolchain). Preserves 90-local.conf and custom *.conf drop-ins. |
pkg-slim ignore-dir <dir>... |
Appends <dir>/* to the managed 90-local.conf file. |
pkg-slim ignore <glob>... |
Appends exact file or glob patterns to 90-local.conf. |
pkg-slim disable |
Removes all *.conf files under /usr/local/etc/pkg/daemonless-slim.d/ to restore stock pkg extraction behavior. |
pkg-slim status |
Prints active drop-ins and the merged FILES_IGNORE_GLOB patterns reported by pkg config. Exits non-zero if drop-ins exist but pkg reports 0 patterns. |
Custom rules and path safety
90-local.conf is managed by pkg-slim and should not be edited by hand; put hand-written UCL rules in a separate *.conf file under /usr/local/etc/pkg/daemonless-slim.d/. Paths passed to --ignore-dir and --ignore must live under /usr/local/, be at least one directory below /usr/local/, and cannot start with a wildcard top-level component.
Containerfile Patterns
Standard Runtime Image
Enable all default tiers (docs dev toolchain) right before installing runtime packages:
Multi-Stage Builds
Leave the builder stage untouched so compilers, headers, and static libraries install normally during compilation, and enable pkg-slim only in the final production stage:
App-Specific Ignore Patterns
Add extra directories or globs inline with enable (or separately with pkg-slim ignore-dir / pkg-slim ignore):
Selective Tiers or Opting Out
If an application needs headers at runtime (for example, building native plugins on startup), enable only the safe tiers:
If an image needs documentation or man pages (which base-core skips by default via 10-docs.conf), disable pkg-slim before installing packages:
Building Downstream Images (FROM a Slimmed Image)
pkg-slim remains enabled in the final runtime image. If you write a downstream Containerfile FROM a slimmed image (for example, compiling a PostgreSQL extension FROM ghcr.io/daemonless/postgres) and need headers or compiler tools back:
- Run
pkg-slim disablesopkgextracts headers and toolchains again. - Reinstall the already-installed parent packages with
pkg install -fysopkgre-extracts the files that were skipped when the parent image was built.
Why -fy is required
Running pkg install -y without -f treats packages already installed in the parent image as up to date and will not re-extract their skipped headers or static libraries.
Verifying a Slimmed Image
After enabling pkg-slim in an image, verify both package integrity and runtime shared libraries before publishing:
-
Check active profile:
All three default tiers (10-docs.conf,20-dev.conf,30-toolchain.conf) report 50 active patterns. -
Check package checksums:
Confirm exit code0with no missing-file errors. -
Check ELF shared library links: Scan binaries and shared libraries under
/usr/localwithlddto verify no runtime binary lost a required.sodependency. -
Run CIT and feature checks: Run
dbuild test(orbuild-test.sh) and exercise runtime features that depend on preserved libraries (such as LLVM JIT queries in PostgreSQL or hardware transcoding in media apps).