๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Next.js

[๋‚ด๋ณด๋‚ด๋ฒˆ] Next.js docs - Deployment

๋‚ด๋ณด๋‚ด๋ฒˆ(๋‚ด๊ฐ€ ๋ณด๋ ค๊ณ  ๋‚ด๊ฐ€ ๋ฒˆ์—ญํ•œ...) Next.js docs

2021๋…„ 7์›” 11์ผ ๊ธฐ์ค€ Next.js ๊ณต์‹ ๋ฌธ์„œ๋ฅผ ๋ฒˆ์—ญํ–ˆ๋‹ค.

โ€ป ์˜์–ด ์ „๊ณต์ž๋„ ํ•ด์™ธ ์œ ํ•™ํŒŒ๋„ ์•„๋‹ˆ๊ธฐ์— ๋ฒˆ์—ญ์—๋Š” ์˜์—ญ, ์˜ค์—ญ, ๊ตฌ๊ธ€ ๋ฒˆ์—ญ์ด ๋ฌด์ˆ˜ํžˆ ๋งŽ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํ˜ผ์ž ๊ณต์‹๋ฌธ์„œ๋ฅผ ์ฐธ์กฐํ•ด๊ฐ€๋ฉฐ ๋ฒˆ์—ญํ•˜๋‹ค ๋ณด๋‹ˆ ์˜คํƒ€๋„ ๋งŽ์„ ์ˆ˜ ์žˆ๋‹ค. ์ •ํ™•ํ•œ ๋‚ด์šฉ์€ ๊ณต์‹๋ฌธ์„œ๋ฅผ ์ง์ ‘ ์‚ดํŽด๋ณด๊ฑฐ๋‚˜ ๋‹ค๋ฅธ ์ •๋ณด๋“ค์„ ๋” ์ฐพ์•„๋ณด๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค.

(ํ•˜์ง€๋งŒ ๋Œ“๊ธ€ ํ”ผ๋“œ๋ฐฑ๋„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค๐Ÿ˜ƒ )

Next.js ๊ณต์‹๋ฌธ์„œ ํ™•์ธํ•˜๊ธฐ>>

 

Deployment | Next.js

Deploy your Next.js app to production with Vercel and other hosting options.

nextjs.org

 

Vercel(Recommended) 

The easiest way to deploy Next.js to production is to use the Vercel platform from the creators of Next.js. Vercel is a cloud platform for static sites, hybrid apps, and Serverless Functions.

Next.js๋ฅผ production์œผ๋กœ ๋ฐฐํฌํ•˜๋Š” ๊ฐ€์žฅ ์‰ฌ์šด ๋ฐฉ๋ฒ•์€ Next.js๋ฅผ ๋งŒ๋“  Vercel ํ”Œ๋žซํผ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. Vercel์€ ์ •์  ์‚ฌ์ดํŠธ, ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ์•ฑ, Serverless function๋“ค์„ ์œ„ํ•œ ํด๋ผ์šฐ๋“œ ํ”Œ๋žซํผ์ด๋‹ค.

Getting started

If you haven’t already done so, push your Next.js app to a Git provider of your choice: GitHub, GitLab, or BitBucket. Your repository can be private or public.
์ด๋ฏธ Git์œผ๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ์ง€ ์•Š๋‹ค๋ฉด ๋‹น์‹ ์˜ ์„ ํƒ์— ๋”ฐ๋ผ Git provider(GitHub, GitLab, BitBucket)์— ๋‹น์‹ ์˜ Next.js ์•ฑ์„ ์˜ฌ๋ฆฌ์ž. ์ฝ”๋“œ ์ €์žฅ์†Œ๋Š” private, public ๋ฌด๋ฐฉํ•˜๋‹ค.

Then, follow these steps: 
๊ทธ๋ฆฌ๊ณ ๋Š” ์•„๋ž˜์˜ ์ˆœ์„œ๋Œ€๋กœ ๋”ฐ๋ผ๊ฐ€์ž: 

  1. Sign up to Vercel (no credit card is required).
    Vercel์— ๊ฐ€์ž…ํ•œ๋‹ค(์‹ ์šฉ์นด๋“œ ์ •๋ณด๋ฅผ ์š”๊ตฌํ•˜์ง€ ์•Š์Œ).
  2. After signing up, you’ll arrive on the “Import Project” page. Under “From Git Repository”, choose the Git provider you use and set up an integration. (Instructions: GitHub / GitLab / BitBucket).
    ๊ฐ€์ž…ํ›„์—, Import Project ํŽ˜์ด์ง€๊ฐ€ ๋ณด์ผ ๊ฒƒ์ด๋‹ค. From Git Repository ์•„๋ž˜์—์„œ ๋‹น์‹ ์ด ์‚ฌ์šฉํ•˜๋Š” Git ์ œ๊ณต์ž๋ฅผ ์„ ํƒํ•˜๊ณ  ํ†ตํ•ฉ ์„ค์ •์„ ํ•œ๋‹ค. (๊ฐ Git ์ œ๊ณต์ž ๋ณ„ ์„ค๋ช…: GitHub/GitLab/BitBucket)
  3. Once that’s set up, click “Import Project From …” and import your Next.js app. It auto-detects that your app is using Next.js and sets up the build configuration for you. No need to change anything — everything should work just fine!
    ์„ค์ •์ด ์™„๋ฃŒ๋˜๋ฉด Import Project From์„ ํด๋ฆญํ•˜๊ณ  ๋‹น์‹ ์˜ Next.js ์•ฑ์„ ๊ฐ€์ ธ์˜ค์ž. ๋‹น์‹ ์˜ ์•ฑ์ด Next.js๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”์ง€ ์ž๋™ ๊ฐ์ง€๋˜๊ณ  ๋นŒ๋“œ ํ™˜๊ฒฝ์„ค์ •์„ ํ•ด์ค€๋‹ค. ์–ด๋–ค ๊ฒƒ๋„ ๋ณ€๊ฒฝํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค. — ๋ชจ๋“  ๊ฒƒ์ด ์ œ๋Œ€๋กœ ๋™์ž‘ํ•  ๊ฒƒ์ด๋‹ค! 
  4. After importing, it’ll deploy your Next.js app and provide you with a deployment URL. Click “Visit” to see your app in production.
    ๊ฐ€์ ธ์˜ค๊ณ  ๋‚œ ํ›„์—, ๋‹น์‹ ์˜ Next.js ์•ฑ์„ ๋ฐฐํฌํ•˜๊ณ  ๋ฐฐํฌ URL์„ ์ œ๊ณตํ•ด์ค„ ๊ฒƒ์ด๋‹ค. Visit์„ ํด๋ฆญํ•ด์„œ production ์ƒํƒœ์˜ ๋‹น์‹ ์˜ ์•ฑ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. 

Congratulations! You’ve just deployed your Next.js app! If you have questions, take a look at the Vercel documentation.
์ถ•ํ•˜ํ•œ๋‹ค! ๋ฐฉ๊ธˆ ๋ง‰ ๋‹น์‹ ์˜ Next.js ์•ฑ์„ ๋ฐฐํฌํ–ˆ๋‹ค! ๊ถ๊ธˆํ•œ ์‚ฌํ•ญ์ด ์žˆ๋‹ค๋ฉด Vercel ๊ณต์‹๋ฌธ์„œ๋ฅผ ๋ณด๋ผ. 

If you’re using a custom server, we strongly recommend migrating away from it (for example, by using 
dynamic routing). If you cannot migrate, consider other hosting options.
์ปค์Šคํ…€ ์„œ๋ฒ„๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค๋ฉด, ๋ฒ—์–ด๋‚˜๋Š” ๊ฒƒ์„(์ปค์Šคํ…€ ์„œ๋ฒ„์—์„œ Next.js ์ž์ฒด ์„œ๋ฒ„๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•˜๋Š” ๊ฒƒ ๊ฐ™์Œ.) ๊ฐ•๋ ฅํžˆ ์ถ”์ฒœํ•œ๋‹ค. (์˜ˆ๋ฅผ ๋“ค๋ฉด, ๋™์  ๋ผ์šฐํŒ… ์‚ฌ์šฉ). ๊ทธ๋ ‡๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ๋‹ค๋ฅธ ํ˜ธ์ŠคํŒ… ์˜ต์…˜์„ ๊ณ ๋ คํ•ด๋ณด๋ผ. 

DPS: Develop, Preview, Ship

Let’s talk about the workflow we recommend using. Vercel supports what we call the DPS workflow: Develop, Preview, and Ship:
์šฐ๋ฆฌ๊ฐ€ ์ถ”์ฒœํ•˜๋Š” ์›Œํฌํ”Œ๋กœ์šฐ์— ๋Œ€ํ•ด์„œ ์ด์•ผ๊ธฐํ•ด๋ณด์ž. Vercel์€ DPS: Develop, Preview ๊ทธ๋ฆฌ๊ณ  Ship์ด๋ผ๊ณ  ๋ถ€๋ฅด๋Š” ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์ง€์›ํ•œ๋‹ค:

  • Develop: Write code in Next.js. Keep the development server running and take advantage of React Fast Refresh.
    Develop: Next.js๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. ๊ฐœ๋ฐœ ์„œ๋ฒ„๋ฅผ ๊ณ„์† ๋™์ž‘ํ•˜๊ฒŒ ํ•จ์œผ๋กœ React Fast Refresh๋ฅผ ํ™œ์šฉํ•œ๋‹ค. 
    2021.04.03 - [Next.js] - [๋‚ด๋ณด๋‚ด๋ฒˆ] Next.js docs - Fast Refresh
  • Preview: Every time you push changes to a branch on GitHub / GitLab / BitBucket, Vercel automatically creates a new deployment with a unique URL. You can view them on GitHub when you open a pull request, or under “Preview Deployments” on your project page on Vercel. Learn more about it here.
    Preview: ๋งค๋ฒˆ ๋ณ€๊ฒฝ๋œ ์ฝ”๋“œ๋ฅผ GitHub / GitLab / BitBucket์— ์˜ฌ๋ฆด ๋•Œ, Vercel์€ ์ž๋™์œผ๋กœ ์ƒˆ๋กœ์šด ๋ฐฐํฌ์— ๋Œ€ํ•œ ๊ณ ์œ  URL์„ ์ƒ์„ฑํ•œ๋‹ค. GitHub์—์„œ pull request๋ฅผ ์—ด ๋•Œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ณ  Vercel์˜ ๋‹น์‹ ์˜ ํ”„๋กœ์ ํŠธ ํŽ˜์ด์ง€์—์„œ Preview Deployments์—์„œ๋„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๊ธฐ์„œ ๋” ๋ฐฐ์›Œ๋ณด์ž.
  • Ship: When you’re ready to ship, merge the pull request to your default branch (e.g. main). Vercel will automatically create a production deployment.
    Ship: ๋ฐฐํฌํ•  ์ค€๋น„๊ฐ€ ๋˜๋ฉด pull request๋ฅผ ๊ธฐ๋ณธ ๋ธŒ๋žœ์น˜(์˜ˆ์‹œ. main)์— ๋ณ‘ํ•ฉํ•œ๋‹ค. Vercel์€ ์ž๋™์œผ๋กœ production ๋ฐฐํฌ๋ฅผ ์ƒ์„ฑํ•  ๊ฒƒ์ด๋‹ค. 

By using the DPS workflow, in addition to doing code reviews, you can do deployment previews. Each deployment creates a unique URL that can be shared or used for integration tests.
DPS ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ ๋ฆฌ๋ทฐ์™€ ๋ฐฐํฌ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ฐ ๋ฐฐํฌ๋งˆ๋‹ค ๊ณต์œ ๋˜๊ฑฐ๋‚˜ ํ†ตํ•ฉ ํ…Œ์ŠคํŠธ์— ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๋Š” ๊ณ ์œ ํ•œ URL์ด ์ƒ์„ฑ๋œ๋‹ค. 

Optimized for Next.js

Vercel is made by the creators of Next.js and has first-class support for Next.js.
Vercel์€ Next.js์˜ ๊ฐœ๋ฐœ์ž๋“ค์— ์˜ํ•ด ๋งŒ๋“ค์–ด์กŒ๊ณ  Next.js์— ๋Œ€ํ•œ ์ตœ๊ณ  ์ˆ˜์ค€์˜ ์ง€์›์„ ์ œ๊ณตํ•œ๋‹ค. 

For example, the hybrid pages approach is fully supported out of the box.
์˜ˆ๋ฅผ ๋“ค๋ฉด, ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ํŽ˜์ด์ง€๋“ค์˜ ์ ‘๊ทผ์— ๋Œ€ํ•ด ๊ธฐ๋ณธ์ ์œผ๋กœ ์™„๋ฒฝํžˆ ์ง€์›ํ•œ๋‹ค. 
*ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ํŽ˜์ด์ง€: 2021.03.29 - [Next.js] - [๋‚ด๋ณด๋‚ด๋ฒˆ] Next.js docs - Pages

  • Every page can either use Static Generation or Server-Side Rendering.
    ๊ฐ ํŽ˜์ด์ง€๋Š” ์ •์  ์ƒ์„ฑ ํ˜น์€ ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
  • Pages that use Static Generation and assets (JS, CSS, images, fonts, etc) will automatically be served from Vercel's Edge Network, which is blazingly fast.
    ์ •์  ์ƒ์„ฑ๊ณผ assets(JS, CSS, ์ด๋ฏธ์ง€, ํฐํŠธ ๋“ฑ๊ณผ ๊ฐ™์€)์„ ์‚ฌ์šฉํ•˜๋Š” ํŽ˜์ด์ง€๋“ค์€ ๋งค์šฐ ๋น ๋ฅธ Vercel์˜ Edge Network์—์„œ ์ž๋™์œผ๋กœ ์ œ๊ณตํ•œ๋‹ค.  
  • Pages that use Server-Side Rendering and API routes will automatically become isolated Serverless Functions. This allows page rendering and API requests to scale infinitely.
    ์„œ๋ฒ„์‚ฌ์ด๋“œ ๋ Œ๋”๋ง๊ณผ API ๋ผ์šฐํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํŽ˜์ด์ง€๋“ค์€ ์ž๋™์œผ๋กœ ๊ฒฉ๋ฆฌ๋œ Serverless Functions์ด ๋  ๊ฒƒ์ด๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ํŽ˜์ด์ง€ ๋ Œ๋”๋ง๊ณผ API ์š”์ฒญ์„ ๋ฌดํ•œ์œผ๋กœ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๋‹ค. 

Custom Domains, Environment Variables, Automatic HTTPS, and more

  • Custom Domains: Once deployed on Vercel, you can assign a custom domain to your Next.js app. Take a look at our documentation here.
    ์ปค์Šคํ…€ ๋„๋ฉ”์ธ: Vercel์— ๋ฐฐํฌ๋˜๋ฉด, ์ปค์Šคํ…€ ๋„๋ฉ”์ธ์„ ๋‹น์‹ ์˜ Next.js ์•ฑ์— ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋‹ค. ์šฐ๋ฆฌ์˜ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•ด๋ณด๋ผ. 
  • Environment Variables: You can also set environment variables on Vercel. Take a look at our documentation here. You can then use those environment variables in your Next.js app.
    ํ™˜๊ฒฝ๋ณ€์ˆ˜: Vercel์—์„œ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์—ญ์‹œ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ์—ฌ๊ธฐ์„œ ์šฐ๋ฆฌ์˜ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•ด๋ณด๋ผ. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์ด๋Ÿฌํ•œ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋“ค์„ ๋‹น์‹ ์˜ Next.js ์•ฑ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. 
  • Automatic HTTPS: HTTPS is enabled by default (including custom domains) and doesn't require extra configuration. We auto-renew SSL certificates.
    ์ž๋™ HTTPS: HTTPS๊ฐ€ ๊ธฐ๋ณธ์ ์œผ๋กœ ํ™œ์„ฑํ™”๋˜์–ด ์žˆ๊ณ (์ปค์Šคํ…€ ๋„๋ฉ”์ธ์„ ํฌํ•จํ•ด์„œ) ์ถ”๊ฐ€์ ์ธ ์„ค์ •์ด ํ•„์š”์—†๋‹ค. ์šฐ๋ฆฌ๊ฐ€ SSL ์ธ์ฆ์„œ๋ฅผ ์ž๋™ ๊ฐฑ์‹ ํ•œ๋‹ค. 
  • More: Read our documentation to learn more about the Vercel platform.
    ์ถ”๊ฐ€์ ์œผ๋กœ: ์šฐ๋ฆฌ์˜ ๋ฌธ์„œ๋ฅผ ์ฝ์–ด๋ณด๊ณ  Vercel ํ”Œ๋žซํผ์— ๋Œ€ํ•ด์„œ ๋” ๋งŽ์€ ์ ๋“ค์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋ผ. 

Automatic Updates

When you deploy your Next.js application, you want to see the latest version without needing to reload.
Next.js ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ฐฐํฌํ•  ๋•Œ ๋ฆฌ๋กœ๋“œ ํ•  ํ•„์š”๊ฐ€ ์—†์ด ์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ๋ณด๊ณ  ์‹ถ์„ ๊ฒƒ์ด๋‹ค. 

Next.js will automatically load the latest version of your application in the background when routing. For client-side navigation, next/link will temporarily function as a normal <a> tag.
Next.js๋Š” ๋ผ์šฐํŒ…ํ•  ๋•Œ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์ž๋™์œผ๋กœ ์ตœ์‹  ๋ฒ„์ „์„ ๋กœ๋“œํ•œ๋‹ค. ํด๋ผ์ด์–ธํŠธ ์ธก์˜ ๋‚ด๋น„๊ฒŒ์ด์…˜์—์„œ next/link๋Š” ์ผ์‹œ์ ์œผ๋กœ ๋ณดํ†ต์˜ <a> ํƒœ๊ทธ๋กœ ๋™์ž‘ํ•  ๊ฒƒ์ด๋‹ค. 

If a new page (with an old version) has already been prefetched by next/link, Next.js will use the old version. Then, after either a full page refresh or multiple client-side transitions, Next.js will show the latest version.
๋งŒ์•ฝ ์ƒˆ๋กœ์šด ํŽ˜์ด์ง€๊ฐ€(์ด์ „ ๋ฒ„์ „ ํฌํ•จ) next/link์— ์˜ํ•ด์„œ ํ”„๋ฆฌํŒจ์น˜๋œ ๊ฒฝ์šฐ, Next.js๋Š” ์ด์ „ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•œ๋‹ค. ๊ทธ๋‹ค์Œ ์ „์ฒด ํŽ˜์ด์ง€๊ฐ€ ์ƒˆ๋กœ๊ณ ์นจ ๋˜๊ฑฐ๋‚˜ ํด๋ผ์ด์–ธํŠธ ์ธก์˜ ์—ฌ๋Ÿฌ ๋ฒˆ์˜ ์ „ํ™˜ ํ›„์— Next.js๋Š” ์ตœ์‹  ๋ฒ„์ „์„ ํ‘œ์‹œํ•  ๊ฒƒ์ด๋‹ค. 

 

Other hosting options

Node.js Server

Next.js can be deployed to any hosting provider that supports Node.js. This is the approach you should take if you’re using a custom server.
Next.js๋Š” Node.js๋ฅผ ์ง€์›ํ•˜๋Š” ์–ด๋–ค ํ˜ธ์ŠคํŒ… ์ œ๊ณต์ž์—์„œ๋“  ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜๋Š” ๋‹น์‹ ์ด ์ปค์Šคํ…€ ์„œ๋ฒ„๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋ผ๋ฉด ๋”ฐ๋ผ์•ผ ํ•˜๋Š” ์ ‘๊ทผ๋ฐฉ์‹์ด๋‹ค.

Make sure your package.json has the "build" and "start" scripts:
๋‹น์‹ ์˜ package.json์— build์™€ start ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋ผ: 

{
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  }
}

 

'next build' builds the production application in the '.next' folder. After building, 'next start' starts a Node.js server that supports hybrid pages, serving both statically generated and server-side rendered pages.
'next build'๋Š” .next ํด๋”์— production ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋นŒ๋“œํ•œ๋‹ค. ๋นŒ๋“œ ํ›„์— 'next start'๋Š” ์ •์  ์ƒ์„ฑ, ์„œ๋ฒ„ ์‚ฌ์ด๋“œ ๋ Œ๋”๋ง ํŽ˜์ด์ง€ ๋ชจ๋‘๋ฅผ ์ œ๊ณตํ•˜๋Š” ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ํŽ˜์ด์ง€๋ฅผ ์ง€์›ํ•˜๋Š” Node.js ์„œ๋ฒ„๋ฅผ ์‹œ์ž‘ํ•œ๋‹ค. 

Docker Image

Next.js can be deployed to any hosting provider that supports Docker containers. You can use this approach when deploying to container orchestrators such as Kubernetes or HashiCorp Nomad, or when running inside a single node in any cloud provider.
Next.js๋Š” Docker ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ง€์›ํ•˜๋Š” ์–ด๋–ค ํ˜ธ์ŠคํŒ… ์ œ๊ณต์ž์—์„œ๋“  ๋ฐฐํฌํ•  ์ˆ˜ ์žˆ๋‹ค. ์•„๋ž˜์˜ ์ ‘๊ทผ ๋ฐฉ๋ฒ•์„ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋‚˜ ํ•˜์‹œ์ฝ”ํ”„ ๋…ธ๋งˆ๋“œ์™€ ๊ฐ™์€ ์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ดํ„ฐ์— ๋ฐฐํฌํ•˜๊ฑฐ๋‚˜ ํด๋ผ์šฐ๋“œ ์ œ๊ณต์ž์˜ ๋‹จ์ผ ๋…ธ๋“œ ๋‚ด์—์„œ ์‹คํ–‰ํ•  ๋•Œ ์ด ์ ‘๊ทผ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. 

Here is a multi-stage Dockerfile using node:alpine that you can use:
์•„๋ž˜๋Š” node:alpine์„ ์‚ฌ์šฉํ•œ ๋ฉ€ํ‹ฐ ์Šคํ…Œ์ด์ง€ Dockerfile์ด๋‹ค.

# Install dependencies only when needed
FROM node:alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# Rebuild the source code only when needed
FROM node:alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline

# Production image, copy all the files and run next
FROM node:alpine AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

# You only need to copy next.config.js if you are NOT using the default configuration
# COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

USER nextjs

EXPOSE 3000

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
# ENV NEXT_TELEMETRY_DISABLED 1

CMD ["yarn", "start"]

Make sure to place this Dockerfile in the root folder of your project.
์ด ๋„์ปค ํŒŒ์ผ์„ ํ”„๋กœ์ ํŠธ์˜ ๋ฃจํŠธ ํด๋”์— ๋‘์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๋ผ.

You can build your container with 'docker build . -t my-next-js-app' and run it with 'docker run -p 3000:3000 my-next-js-app'.
'docker build . -t my-next-js-app' ๋ช…๋ น์–ด๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋นŒ๋“œํ•˜๊ณ  'docker run -p 3000:3000 my-next-js-app'๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. 

Static HTML Export

If you’d like to do a static HTML export of your Next.js app, follow the directions on our documentation.
๋งŒ์ผ ๋‹น์‹ ์˜ Next.js ์•ฑ์„ ์ •์  HTML ๋‚ด๋ณด๋‚ด๊ธฐ ํ•˜๊ธฐ๋ฅผ ์›ํ•œ๋‹ค๋ฉด, ์šฐ๋ฆฌ์˜ ๋ฌธ์„œ์— ์žˆ๋Š” ์ง€์นจ์„ ๋”ฐ๋ฅด๋ผ.