skip to Main Content

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


  1. Replace below lines

    ARG NODE_VERSION=18.14.2
    
    FROM node:${NODE_VERSION}-slim as base
    
    FROM oven/bun:1.0.0
    

    with:

    FROM oven/bun:latest AS base
    

    Your issue is because you try to do bun install using the base image (which don’t have bun and instead has node) and hence fails.

    Both node and bun 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 see nuxt is set as devDependencies, which are not installed when using --production flag.

    So replace that with:

    RUN bun install
    
    Login or Signup to reply.
  2. To anyone who installed Bun manually:

    RUN curl -fsSL https://bun.sh/install | bash
    
    

    And got this error:

     > [build 2/5] RUN bun install 
    #12 0.154 /bin/sh: 1: bun: not found
    

    Just add this to your dockerfile:

    RUN ~/.bun/bin/bun install
    

    (:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search