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

Next 14 is not working properly in docker on windows with bun, but normal at local terminal #66068

Open
devhik0 opened this issue May 22, 2024 · 6 comments
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@devhik0
Copy link

devhik0 commented May 22, 2024

Link to the code that reproduces this issue

https://github.com/devhik0/crm-saas

To Reproduce

  1. Look at Docker file and try to build and run it in docker or kubernetes and see the error below.

Current vs. Expected behavior

Expected runs properly, but giving this error

. > kubectl logs client-app-depl-6f88ddb4b5-4z74x
$ next start
  ▲ Next.js 14.2.3
  - Local:        http://localhost:3000

 ✓ Starting...
145 |         var _middlewareManifest_middleware_, _middlewareManifest_middleware;
146 |         const buildIdPath = _path.default.join(opts.dir, opts.config.distDir, _constants.BUILD_ID_FILE);
147 |         try {
148 |             buildId = await _promises.default.readFile(buildIdPath, "utf8");
149 |         } catch (err) {
150 |             if (err.code !== "ENOENT") throw err;


                                                                        ^
error: Could not find a production build in the '.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id
      at /app/node_modules/next/dist/server/lib/router-utils/filesystem.js:150:247

error: script "start" exited with code 1

Provide environment information

OS: Windows 11
Node: 20
Bun: 1

Which area(s) are affected? (Select all that apply)

Runtime

Which stage(s) are affected? (Select all that apply)

next build (local), next start (local)

Additional context

Everything normal at local setup, it's only happens at docker. Also here the link for discussion about this:

#65740

@devhik0 devhik0 added the bug Issue was opened via the bug report template. label May 22, 2024
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label May 22, 2024
@tpdewolf
Copy link

I have the same issue
Next 14.2.3

.next folder in docker only includes these files and folders

cache
prerender-manifest.js
package.json
routes-manifest.json

@devhik0
Copy link
Author

devhik0 commented May 23, 2024

I can't see what it includes cuz it's crashing due to that build error above.

@tpdewolf
Copy link

tpdewolf commented May 23, 2024

@devhik0 You can ssh into the image by running docker run --rm -it myimage:latest sh (replace myimage:latest with your tag)

I do notice that it does work when I build the image in Github actions on ubuntu latest. When i'm building it on Mac m1 with --platform=linux/amd64 it doesnt create all files in .next

@devhik0
Copy link
Author

devhik0 commented May 23, 2024

@tpdewolf Yes, but it's giving same error when I run container and stopping. Weird one, same app is running in GitHub actions machine on Ubuntu, but crashing on Windows. I tried building locally via Dockerfile, but when I run it crashed again cuz of same error.

@Hulow
Copy link

Hulow commented May 27, 2024

hey,
almost the same for me:

  • I use Next.js 14.2.3.
  • The docker image run correctly on my local env but it gets stuck when i run the image on a ubuntu server.
  • I build my image FROM node:20-slim

@devhik0
Copy link
Author

devhik0 commented May 29, 2024

So, update: Check your Dockerfile and other files to make sure its copying all files and have right permissions.
Here i ll share what i changed and how it fixed everything.

# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 as base
WORKDIR /app

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --production

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED 1

# RUN bun run test #todo: add here after adding tests
RUN bun run build

# copy production dependencies and source code into final image
FROM base AS release
WORKDIR /app

# Set correct permissions for nextjs user and don't run as root
RUN adduser crm
RUN chown crm:bun .
USER crm

COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease --chown=crm:bun /app/.next ./.next
COPY --from=prerelease /app/node_modules ./node_modules
COPY --from=prerelease /app/package.json ./package.json
COPY --from=prerelease /app/public ./public
CMD ["bun", "run", "build"]
# run the app
EXPOSE 3000/tcp
CMD ["bun", "start" ]

If needs use it as reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

3 participants