Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running bun nextjs app in docker #4671

Open
abhi12299 opened this issue Sep 9, 2023 · 16 comments
Open

Error running bun nextjs app in docker #4671

abhi12299 opened this issue Sep 9, 2023 · 16 comments
Labels
bug Something isn't working docker An issue that occurs when running in Docker needs investigate Needs to be investigated to find the root cause

Comments

@abhi12299
Copy link

abhi12299 commented Sep 9, 2023

What version of Bun is running?

1.0.0

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

  1. Run bunx create-next-app command to initialise a new nextjs app.

  2. Add the following Dockerfile to the project:

FROM oven/bun:1.0

WORKDIR /app

COPY package.json .

COPY bun.lockb .

RUN bun install

COPY . .

CMD [ "bun", "run", "dev"]
  1. Build the docker image:
docker build -t bunnext:latest .
  1. Run the docker image:
docker run -p 3000:3000 bunnext:latest
  1. Open the browser at localhost:3000 and the container stops without any error message.

What is the expected behavior?

The container should keep running and the web app should load successfully.

What do you see instead?

No response

Additional information

  1. The bun run dev command works fine outside of Docker.
  2. Docker is running on M1.
@abhi12299 abhi12299 added the bug Something isn't working label Sep 9, 2023
@abhi12299
Copy link
Author

abhi12299 commented Sep 9, 2023

Container logs before it stops:

image

@karthik-js
Copy link

@abhi12299 Try running again. It added necessary types to make it typescript worthy. It should work the next time

@abhi12299
Copy link
Author

No luck with that too. Did the necessary changes in tsconfig.json and it still exits without any error message.

// tsconfig.json
{
    "compilerOptions": {
        // ...,
        "plugins": [
            {
                "name": "next"
            }
        ]
    },
    "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"]
}
image

@peterhijma
Copy link

Got the same problem with Nuxt.

@karthik-js
Copy link

karthik-js commented Sep 9, 2023

Observations:

Next.js spawns workers to handle routing etc.

I have created two projects with app router and pages router

When we run the projects locally, they work fine.

But when run in Docker they fail with the same error:
Screenshot 2023-09-10 at 12 35 08 AM

So the possible options to get this result:

  1. Either we are doing something wrong with how we are using the image (which is highly unlikely)
  2. Bun has issues with the creation of workers as the error points out in the screenshot i.e. failing to find port

@peterhijma Most probably the same issue with Nuxt

@ericklarsen
Copy link

ericklarsen commented Sep 9, 2023

@karthik-js I also got quite similiar issue with you. I still can't run my nextjs app with bun run dev.
image

@karthik-js
Copy link

@ericklarsen not sure if that is same issue. It shows in ur error that it is a dom exception. If you can share a repro repo. I will try to debug and help you

@terion-name
Copy link

terion-name commented Sep 9, 2023

Getting in docker:

bun install v1.0.0 (822a00c4)
ERROR  EBADF: Bad file descriptor
at <anonymous> (node_modules/nuxi/dist/shared/nuxi.615ae2d1.mjs:5962:29)
at <anonymous> (node_modules/nuxi/dist/shared/nuxi.31a0124f.mjs:11:30)
...
ERROR  EBADF: Bad file descriptor
Checked 1049 installs across 970 packages (no changes) [1235.00ms]
error: script "postinstall" exited with code 1 (SIGHUP)

@karthik-js
Copy link

Issue is already being tracked by the bun team here: #3776

@abhi12299
Copy link
Author

@karthik-js I think that the issue you're referencing is different from this one. Here it fails inside of docker, works well without it.

@karthik-js
Copy link

Check the 3rd point where he mentions worker threads. It was added to the bun. Now Next.js companion PR has to be merged and needs to be released.

@terion-name
Copy link

Check the 3rd point where he mentions worker threads. It was added to the bun. Now Next.js companion PR has to be merged and needs to be released.

It's not only about Next, seems to be more general

@landsman
Copy link

I noticed a similar thing when I used bun only as a docker image for an app that uses npm as a package manager. I wasn't able to build it inside a docker container.

Step 6/20 : RUN bun run build
 ---> Running in 3c9568b05b80
$ next build
error: script "build" exited with code 11 (SIGSEGV)

@jamierpond
Copy link

@landsman same here

1 similar comment
@karthik-js
Copy link

@landsman same here

@annminn104
Copy link

Observations:

Next.js spawns workers to handle routing etc.

I have created two projects with app router and pages router

When we run the projects locally, they work fine.

But when run in Docker they fail with the same error: Screenshot 2023-09-10 at 12 35 08 AM

So the possible options to get this result:

  1. Either we are doing something wrong with how we are using the image (which is highly unlikely)
  2. Bun has issues with the creation of workers as the error points out in the screenshot i.e. failing to find port

@peterhijma Most probably the same issue with Nuxt

I also got the same error when building with nextjs. My console log also shows the same error. I wonder if you have found any solution

@Electroid Electroid added docker An issue that occurs when running in Docker needs investigate Needs to be investigated to find the root cause labels Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docker An issue that occurs when running in Docker needs investigate Needs to be investigated to find the root cause
Projects
None yet
Development

No branches or pull requests

9 participants