bun
bun copied to clipboard
`bun install --frozen-lockfile` is exceptionally slow in docker [bun 1.1.4]
What version of Bun is running?
1.1.4+fbe2fe0c3
What platform is your computer?
Linux 5.15.146.1-microsoft-standard-WSL2 x86_64 x86_64
What steps can reproduce the bug?
Use this minimal Dockerfile with a nestjs project
FROM oven/bun:1.0.14 as base
WORKDIR /usr/src/app
COPY package.json bun.lockb ./
FROM base as dev
RUN bun i --frozen-lockfile
COPY . .
CMD ["bun", "start"]
FROM base as prod
RUN bun i --production --frozen-lockfile
RUN bun i -D @nestjs/cli
COPY . .
RUN bun run build
EXPOSE 3000
CMD ["bun", "start:prod"]
And see a fresh build take 5 minutes for a bun ci
=> [app internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 359B 0.0s
=> [app internal] load metadata for docker.io/oven/bun:1.0.14 4.2s
=> [app internal] load .dockerignore 0.0s
=> => transferring context: 74B 0.0s
=> [app base 1/3] FROM docker.io/oven/bun:1.0.14@sha256:1e7e5dd2a5403b91714d0fc1b229da085f460a632f0c79037cbb0b60238c6434 0.0s
=> [app internal] load build context 0.0s
=> => transferring context: 41.50kB 0.0s
=> CACHED [app base 2/3] WORKDIR /usr/src/app 0.0s
=> CACHED [app base 3/3] COPY package.json bun.lockb ./ 0.0s
=> [app dev 1/2] RUN bun i --frozen-lockfile 300.8s
=> [app dev 2/2] COPY . . 0.2s
=> [app] exporting to image 2.3s
=> => exporting layers 2.3s
=> => writing image sha256:2424dcd80587dcf05e0fccbad2eb51877edf6bbbe977a0e093a8730620178e3e 0.0s
=> => naming to docker.io/library/cannahub-backend-app
What is the expected behavior?
Fast install, doing the same on my host machine takes a few seconds max even without cache
What do you see instead?
300+ second install
Additional information
No response
FROM oven/bun:1.0.14 as base
This is using Bun v1.0.14
Please try with Bun v1.1.4
Please try with Bun v1.1.4
[+] Building 256.1s (7/9) docker:default
=> [app internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 364B 0.0s
=> [app internal] load metadata for docker.io/oven/bun:1.1.4 2.1s
=> [app internal] load .dockerignore 0.1s
=> => transferring context: 74B 0.0s
=> [app base 1/3] FROM docker.io/oven/bun:1.1.4@sha256:ea572eace71acadb17ea5c408550eafd5ab82f2f6f48c04b906a3091e017cf35 0.0s
=> [app internal] load build context 0.3s
=> => transferring context: 50.98kB 0.2s
=> CACHED [app base 2/3] WORKDIR /usr/src/app 0.0s
=> [app base 3/3] COPY package.json bun.lockb ./ 0.2s
=> [app dev 1/2] RUN bun i --frozen-lockfile 253.3s
=> => # bun install v1.1.4 (fbe2fe0c)
I am having the same issue in my docker image, I tried building from base image oven/bun:1-alpine
and it takes forever to install my svelte app dependencies.
If anyone is stuck at this, as a work-around for this, I install the dependencies using yarn, then build and run using bun.
I added
[install.lockfile]
print = "yarn"
to bunfig.toml
file in project's root, this makes bun create yarn.lock
file as well as bun.lockb
file.
Then I update my docker file to look like this:
# Install using yarn, as bun install has problems with docker
FROM node:lts-alpine AS install
WORKDIR /app
COPY package.json .
COPY yarn.lock .
RUN --mount=type=cache,target=/usr/local/share/.cache yarn install --freeze-lockfile --verbose
# Build and run using bun
FROM oven/bun:1-alpine
WORKDIR /app
COPY --from=install /app /app
COPY . .
RUN bun run build
CMD bun ./build/index.js
The --mount
part in the install command is used to mount yarn cache as a cache-mount, this greatly reduces resulting image size (effectively removes cache from the image), and makes subsequent builds a lot faster.
The end result is that docker build
now finishes in a couple of minutes (from a clean state without any cached images).