I’m trying to do an image of the base project of nuxt3 on production with bun.
However, after doing docker compose up
, I get this error :
=> ERROR [build 2/5] RUN bun install --production 0.2s
------
> [build 2/5] RUN bun install --production:
#12 0.154 /bin/sh: 1: bun: not found
------
executor failed running [/bin/sh -c bun install --production]: exit code: 127
ERROR: Service 'my-app' failed to build : Build failed
I don’t really know what is this error, as I’m a beginner on nuxt and docker.
I have this Dockerfile :
# syntax = docker/dockerfile:1
ARG NODE_VERSION=18.14.2
FROM node:${NODE_VERSION}-slim as base
FROM oven/bun:1.0.0
ARG PORT=3000
ENV NODE_ENV=production
WORKDIR /src
# Build
FROM base as build
COPY --link package.json bun.lockb .
RUN bun install --production
COPY --link . .
RUN bun run build
RUN bun prune
And this is my docker-compose file :
version: "3"
services:
my-app:
build:
context: .
ports:
- "3000:3000"
I try before with npm and it worked.
Do you have any ideas?
2
Answers
Replace below lines
with:
Your issue is because you try to do
bun install
using thebase
image (which don’t havebun
and instead hasnode
) and hence fails.Both
node
andbun
are two different JavaScript runtimes. So don’t use them together.Your second issue is
RUN bun install --production
.If you check your
package.json
file, you shall seenuxt
is set asdevDependencies
, which are not installed when using--production
flag.So replace that with:
To anyone who installed Bun manually:
And got this error:
Just add this to your dockerfile:
(: