Deploy a Next.js app
Introduction
In this guide you will learn how to Dockerize and deploy your Next.js app into Docker Deploy.
Pre-requisites
Before starting this guide, make sure you have:
- A running Next.js app
- An account on Docker Deploy
Dockerize your app
If you can already build a docker image for you app, go to the next step
You need to bring the following files from the Next.js Docker example
Download both files and paste them in the root folder of your project, the same where package.json is.
These files tell Docker how to build the image of your app.
Next, you have to set the output of your app to โstandaloneโ in your next.config.mjs file. So it should like this
With that, you should be able to dockerize your Next.js app.
Build and Deploy with the CLI
Instal the CLI
Run npm i dockerdeploy-cli -g
to install the CLI in your PC.
Then run dd-cli login
to log in your user in the CLI.
Build and Deploy
You can run dd-cli build
to build your docker image and push it to your private repository.
Afterwards, you just need to run dd-cli deploy
to deploy the image that you just build into Docker Deploy.
After deploying, you will get the URL to manage that deployment and the automatically generated URL.
Adjust the port
By default, the deployments created through the CLI will listen to the port 80 of your app, but Next.js exposes port 3000 by default. So you have to go to you deployment in the dashboard, and change the ports section as follows:
to
Ready!
You can now visit your site under the autogenerated dockerdeploy.cloud URL!