How to deploy a Next.js project with docker in Apple M1?

237 Views Asked by At

When I used the app directory way to deploy a Next.js project with my Mac, I got an error.

Here is how the errors come.

Use the App directory way in your project. Load more than 5 images on one page. Have a sharp package in your project. Deploy the project with docker in Mac OS( For me, My mac use a Apple M2 chip)

// npm i sharp

import React from 'react'


import img1 from "./small/img-1.jpg";
import img2 from "./small/img-2.jpg";
import img3 from "./small/img-3.jpg";
import img4 from "./small/img-4.jpg";
import img5 from "./small/img-5.jpg";
import img6 from "./small/img-6.jpg";
import Image from 'next/image';



function Home() {
  return (
    <>
      <Image src={img1} alt="Picture of the author" />
      <Image src={img2} alt="Picture of the author" />
      <Image src={img3} alt="Picture of the author" />
      <Image src={img4} alt="Picture of the author" />
      <Image src={img5} alt="Picture of the author" />
      <Image src={img6} alt="Picture of the author" />
    </>
  )
}

export default Home

Error code

 => ERROR [builder 4/4] RUN yarn build                                                                                        12.1s
------
 > [builder 4/4] RUN yarn build:
1.142 yarn run v1.22.19
1.256 $ next build
5.434 Attention: Next.js now collects completely anonymous telemetry regarding usage.
4.435 This information is used to shape Next.js' roadmap and prioritize features.
4.435 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
4.435 https://nextjs.org/telemetry
4.435 
4.828    ▲ Next.js 14.0.1
4.829 
4.830    Creating an optimized production build ...
11.99 qemu: uncaught target signal 11 (Segmentation fault) - core dumped
12.04 error Command failed with signal "SIGSEGV".
12.04 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
------
Dockerfile:30
--------------------
  28 |     # ENV NEXT_TELEMETRY_DISABLED 1
  29 |     
  30 | >>> RUN yarn build
  31 |     
  32 |     # If using npm comment out above and use below instead
--------------------
ERROR: failed to solve: process "/bin/sh -c yarn build" did not complete successfully: exit code: 1
0

There are 0 best solutions below