Bun is a fast all-in-one JavaScript runtime & toolkit with built-in bundler, test runner, and Node.js-compatible package manager. This guide uses Hono, a lightweight and ultrafast web framework.
# use the official Bun imageFROM oven/bun:1 AS baseWORKDIR /usr/src/app# install dependencies into temp directory# this will cache them and speed up future buildsFROM base AS installRUN mkdir -p /temp/devCOPY package.json bun.lockb /temp/dev/RUN cd /temp/dev && bun install --frozen-lockfile# install with --production (exclude devDependencies)RUN mkdir -p /temp/prodCOPY package.json bun.lockb /temp/prod/RUN cd /temp/prod && bun install --frozen-lockfile --production# copy node_modules from temp directory# then copy all (non-ignored) project files into the imageFROM base AS prereleaseCOPY --from=install /temp/dev/node_modules node_modulesCOPY . .# [optional] tests & buildENV NODE_ENV=productionRUN bun testRUN bun run build# copy production dependencies and source code into final imageFROM base AS releaseCOPY --from=install /temp/prod/node_modules node_modulesCOPY --from=prerelease /usr/src/app/index.ts .COPY --from=prerelease /usr/src/app/package.json .# run the appUSER bunEXPOSE 3000/tcpENTRYPOINT [ "bun", "run", "index.ts" ]