CloudUp

Dockerfile Generator

Bun.js App Dockerfile


Get started with Docker for your JavaScript project with optimized and production-ready configs below

Instructions

To use this Dockerfile for your BunJS backend application, save the Dockerfile and .dockerignore in your project's root directory.

You can now run the following command to build the docker image:

$ docker build -t my_app:v1 .

The -t flag lets us specify a name for the image, and --pull tells Docker to automatically download the latest version of the base image (oven/bun).

To run the built docker image:

$ docker run -it --rm -p 8080:8080 my_app:v1

You should now be able to open the app in your browser on the specified port.

Configure Variables

This is an Open Source project and stays alive because of the DevOps community sharing their time and knowledge.

You can also help by reporting bugs or sharing your configuration on GitHub.

Dockerfile
# Stage 0:
# --------

# Define base image
FROM oven/bun:latest-alpine as base


# Stage 1:
# --------

FROM base AS build
WORKDIR /build
ENV NODE_ENV=production

# Install dependencies for production
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile --production

# Copy remaining files and build the app
COPY . .
RUN bun run build


# Stage 2:
# --------

FROM base AS release
WORKDIR /app

# Copy the built app and required files from previous stage
COPY --from=build /build/node_modules node_modules
COPY --from=build /build/package.json .
COPY --from=build /build/index.ts .

USER bun
EXPOSE 8080

# Start the app
ENTRYPOINT ["bun", "run", "index.ts"]
.dockerignore
node_modules
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
Makefile
helm-charts
.env
.editorconfig
.idea
coverage*