Skip to content

Instantly share code, notes, and snippets.

@bjarneo
Created September 20, 2023 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjarneo/c2848dd6b335975f18cdddb8ad36de79 to your computer and use it in GitHub Desktop.
Save bjarneo/c2848dd6b335975f18cdddb8ad36de79 to your computer and use it in GitHub Desktop.
Dockerfile for bun
# Let us create the build step
FROM oven/bun as builder
# Set the working directory
WORKDIR /bun-builder
# Copy package and bun lock file to the workdir
COPY package.json bun.lockb ./
# Install dependencies
RUN bun install
# Copy our API http server
COPY http.ts ./
# Build the project
RUN bun build --target=bun ./http.ts --outfile=http.js
# Let us create the run step
FROM oven/bun
# Set a new and fresh workdri
WORKDIR /bun-api
# Copy the relevant files we need from the builder
COPY --from=builder /bun-builder/http.js ./
COPY --from=builder /bun-builder/package.json ./
# Start the application
CMD [ "bun", "http.js" ]
# Notes:
# If you have production dependencies you have to install those in the last steps.
# You most likely have to compile more code as well, not only one file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment