Skip to content

Instantly share code, notes, and snippets.

@bozdoz
Created November 9, 2025 02:25
Show Gist options
  • Select an option

  • Save bozdoz/2d425ff3b4857fd1c2ba1c84494122fb to your computer and use it in GitHub Desktop.

Select an option

Save bozdoz/2d425ff3b4857fd1c2ba1c84494122fb to your computer and use it in GitHub Desktop.
bun-docker-scratch
# ---- Build stage ----
FROM oven/bun AS builder
WORKDIR /app
# Install TINI
RUN apt-get update && \
apt-get install -y --no-install-recommends tini && \
rm -rf /var/lib/apt/lists/* && \
# Copy tini (ARM64 version)
cp /usr/bin/tini /tini && \
chmod +x /tini
# Basic app, no node_modules
COPY index.ts .
# Compile Bun binary
RUN bun build index.ts --compile --minify --outfile app
# Copy glibc files to a separate layer
# discovered by `ldd app`
RUN mkdir -p /glibc && \
cp -v /lib/ld-linux-aarch64.so.1 /glibc/ && \
cp -v /lib/aarch64-linux-gnu/libc.so.6 /glibc/ && \
cp -v /lib/aarch64-linux-gnu/libm.so.6 /glibc/ && \
cp -v /lib/aarch64-linux-gnu/libdl.so.2 /glibc/ && \
cp -v /lib/aarch64-linux-gnu/libpthread.so.0 /glibc/
# ---- Final scratch image ----
FROM scratch
# Copy Bun binary
COPY --from=builder /app/app /app
# Copy glibc files
COPY --from=builder /glibc /lib
# Minimal required config files
COPY --from=builder /etc/nsswitch.conf /etc/nsswitch.conf
COPY --from=builder /etc/localtime /etc/localtime
COPY --from=builder /usr/share/locale/ /usr/share/locale/
# Copy TINI
COPY --from=builder /tini /tini
# Set loader environment
ENV LD_LIBRARY_PATH=/lib
# for handling SIGINT
ENTRYPOINT ["/tini", "--"]
CMD ["/app"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment