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

Cannot run latest Next.js in Docker #36553

Closed
1 task done
iMerica opened this issue Apr 28, 2022 · 3 comments
Closed
1 task done

Cannot run latest Next.js in Docker #36553

iMerica opened this issue Apr 28, 2022 · 3 comments
Labels
bug Issue was opened via the bug report template.

Comments

@iMerica
Copy link

iMerica commented Apr 28, 2022

Verify canary release

  • I verified that the issue exists in Next.js canary release

Provide environment information

Docker:
Docker version 20.10.14, build a224086

Next: "12.1.5"

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Docker

Describe the Bug

Cannot run Next.js in Docker or in any Cloud Native style using containers.

Expected Behavior

I expect dependencies to be explicit and next.js to build in Docker

To Reproduce

Steps to Reproduce

Generate a new Next.js project using Next.js

npx create-next-app@latest

Create a Dockerfile

FROM node:14-buster-slim
WORKDIR /app
COPY package*.json ./
RUN yarn add -D @swc/cli @swc/core
RUN yarn install
COPY . .
CMD yarn run dev

Run this container locally in Docker:

$ docker-compose up -d
....
next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Loaded env from /app/.env
info  - Attempted to load @next/swc-linux-x64-gnu, but it was not installed
info  - Attempted to load @next/swc-linux-x64-gnux32, but it was not installed
info  - Attempted to load @next/swc-linux-x64-musl, but it was not installed
error - Failed to load SWC binary for linux/x64, see more info here: https://nextjs.org/docs/messages/failed-loading-swc
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@iMerica iMerica added the bug Issue was opened via the bug report template. label Apr 28, 2022
@timjanssen95
Copy link

Hi iMerica!

I would recommend to take a look at the new standalone feature announced in NextJS 12.1. It will reduce your Docker image drastically.

Docs: https://nextjs.org/docs/advanced-features/output-file-tracing#automatically-copying-traced-files-experimental

There are also example Dockerfiles available in two flavours:

I hope this helps out!

Kind regards,
Tim Janssen

@balazsorban44
Copy link
Member

balazsorban44 commented Apr 29, 2022

@timjanssen95 is correct, that's the recommended way to deploy to Docker now.

In some cases your package manager (e.g. npm) might have generated a lockfile that only includes optionalDependencies specific to the platform it was generated on, preventing the optionalDependency needed for your Docker image environment from being installed.

With the latest canary, we will now try to patch the lockfile if that's the case: #36527

But the best solution is to make sure that the lockfile generated is in accordance with the build environment, or upgrade your package manager (eg.: npm i -g npm@latest)

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

3 participants