Docker
Hokusai 2 needs libvips 8.16 or newer. Ubuntu 24.04 LTS ships 8.15 and Debian 12 an older one, so apt install libvips-dev is not enough there: the build fails because older versions are rejected at compile time. Debian 13 and Ubuntu 25.10 and newer ship 8.16 or later, but official Swift images are not published for them, so the Dockerfile below builds libvips from a release tarball in the build stage and copies it into a slim runtime image. It is the same approach Hokusai’s own CI uses to pin a native baseline.
The Dockerfile
Section titled “The Dockerfile”# Hokusai 2 needs libvips 8.16 or newer, which Ubuntu 24.04 does not ship (it has 8.15).# This image builds libvips from a release tarball in the build stage and copies it to a slim runtime.
# ---- build ----------------------------------------------------------------FROM swift:6.2-noble AS buildARG VIPS_VERSION=8.16.1
RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential meson ninja-build pkg-config curl xz-utils ca-certificates \ libglib2.0-dev libexpat1-dev libjpeg-turbo8-dev libpng-dev libwebp-dev libtiff-dev \ libheif-dev libcairo2-dev libpango1.0-dev libfontconfig1-dev \ && rm -rf /var/lib/apt/lists/*
RUN curl -fsSL "https://github.com/libvips/libvips/releases/download/v${VIPS_VERSION}/vips-${VIPS_VERSION}.tar.xz" | tar -xJ -C /tmp \ && cd "/tmp/vips-${VIPS_VERSION}" \ && meson setup build --prefix=/opt/vips --libdir=lib --buildtype=release \ -Dintrospection=disabled -Dmodules=disabled -Dexamples=false \ && meson install -C build \ && rm -rf /tmp/vips-*
ENV PKG_CONFIG_PATH=/opt/vips/lib/pkgconfigWORKDIR /srcCOPY app/ .RUN swift build -c release --product Resizer
# ---- runtime --------------------------------------------------------------FROM ubuntu:nobleRUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0t64 libexpat1 libjpeg-turbo8 libpng16-16t64 libwebp7 libwebpmux3 libwebpdemux2 libtiff6 \ libheif1 libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libfontconfig1 \ fonts-dejavu-core ca-certificates \ && rm -rf /var/lib/apt/lists/*COPY --from=build /opt/vips /opt/vipsCOPY --from=build /usr/lib/swift/linux/*.so* /usr/lib/swift/linux/COPY --from=build /src/.build/release/Resizer /usr/local/bin/resizerENV LD_LIBRARY_PATH=/opt/vips/lib:/usr/lib/swift/linuxRUN useradd --system --create-home appUSER appENTRYPOINT ["resizer"]It was built and run for this page (the image is about 323 MB):
$ docker build -t hokusai-docs-check examples/docker$ docker run --rm hokusai-docs-checklibvips 8.16.1, Cairo 1.18.0can write: jpeg, pdf, png, tiff, webpresized to 32 × 32, 516 bytes (webp)The application in examples/docker/app is a few lines: it prints Hokusai.capabilities(), resizes a generated image and encodes WebP.
Choices in the Dockerfile
Section titled “Choices in the Dockerfile”- Multi-stage. The
swiftimage has the toolchain and compilers; the runtime is a plainubuntu:noblewith only the shared libraries libvips needs. The Swift runtime libraries (/usr/lib/swift/linux/*.so) are copied from the build stage, which is how the container runs without a toolchain;--static-swift-stdlibis an alternative. VIPS_VERSION. Pin it as a build argument and bump it deliberately.hokusai infoshows what the container has.- Libraries are what you install. The build above had no palette, AVIF, HEIF encoder or GIF libraries in the image, and the program’s
capabilities()said so:can write: jpeg, pdf, png, tiff, webp. A libvips build supports only what its dependencies provide at build time, so add the corresponding-devpackages (and their runtime packages in the final stage) for each format you need, then checkcapabilities()again. Do not assume a codec is present: ask the runtime (capabilities). - Fonts. Text rendering needs fonts in the runtime image (
fonts-dejavu-coreabove) and a libvips built with Pango;TextStyle(fontFile:)loads a file you ship. - A non-root user runs the process.
Running a server
Section titled “Running a server”For a Vapor or Hummingbird service replace the Resizer product with your own, expose the port, and set RuntimeConfiguration at startup. In a container, set maxConcurrentEvaluations and maxQueuedEvaluations from the CPU and memory limits you give it: memory is roughly the concurrent evaluations times the decoded size of the images they hold (performance). Set blockUntrustedOperations for services that decode uploads from untrusted users.