Skip to content

Instantly share code, notes, and snippets.

@duongdam
Last active April 15, 2024 09:22
Show Gist options
  • Save duongdam/7fbcdf02c38b58a61d3a18c5b9732136 to your computer and use it in GitHub Desktop.
Save duongdam/7fbcdf02c38b58a61d3a18c5b9732136 to your computer and use it in GitHub Desktop.
Dockerfile for Bun API with size reduced to 298Mb
#Simple size about 298Mb. Bun v1.0.21
FROM oven/bun:latest as build-stage
WORKDIR /dist
COPY . .
COPY .env.production .env
COPY package.json package.json
COPY bun.lockb bun.lockb
# Firebase staging
#COPY firebase/stg.json stg.json
# Firebase Production
#COPY firebase/prod.json prod.json
RUN bun install
RUN bun build ./server.js --outfile server --compile
# Reduce image size
# FROM --platform=linux/amd64 oven/bun:latest if error occurs with platform, but in v1.0.0 it should be fixed
FROM oven/bun:latest
WORKDIR /app
COPY --from=build-stage /dist/.env ./.env
#COPY --from=build-stage /dist/stg.json ./firebase/stg.json
COPY --from=build-stage /dist/server ./server
EXPOSE 8080
ENV PORT 8080
# set hostname to localhost - Use when deploying to Google Cloud Run
ENV HOSTNAME "0.0.0.0"
CMD ["./server"]
# Simple source used Bun with express api,visit https://github.com/duongdam/bun-server-js (branch main and main-typescript)
@duongdam
Copy link
Author

duongdam commented Aug 4, 2023

Ảnh màn hình 2024-01-05 lúc 12 06 36

Ảnh màn hình 2024-01-05 lúc 12 06 58

@jimfilippou
Copy link

You're awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment