Hosting a Next.js web app with Serverless Containers
Next.js is a powerful React framework for building fast, scalable web applications with server-side rendering and static site generation. Hosting Next.js on Scaleway Serverless Containers provides automatic scaling, simplified deployment, and minimal infrastructure management. This approach lets your application efficiently handle dynamic traffic, optimize resource usage, while you can focus on writing code and developing features rather than maintaining servers.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- Installed Docker or Docker Egine
- Created a Scaleway Container Registry namespace and logged into it
Create and host a basic Next.js web application
To host a Next.js web app on Serverless Containers, you must create a Next.js project, implement your pages and any API routes, and add a production-ready Dockerfile that builds and serves the app — either by running a Node server with next build && next start
or by exporting static files with next export
if your app is fully static. Build the container image locally, push it to the Scaleway Container Registry, and deploy it to Scaleway Serverless Containers.
Create your app and test it locally
-
In a terminal, run the command below to create a new folder and access it:
mkdir my-nextjs-app cd my-nextjs-app
-
Run the command below to create an example Next.js application using the default template. You can also use an example from the official Next.js GitHub repository.
npx create-next-app@latest my-nextjs-app
-
When prompted, configure your app according to your needs, or keep the default values to start quickly. Next.js will then create an app with a folder structure similar to the following:
my-nextjs-app/ ├── app/ # Core: Routes using the App Router │ ├── layout.tsx # Root layout (shared across pages) │ ├── page.tsx # Homepage (http://localhost:3000) │ └── globals.css # Global styles │ ├── public/ # Static assets (served at /) │ ├── logo.svg │ └── favicon.ico │ ├── components/ # (Optional) Your reusable components │ └── ... │ ├── styles/ # (Optional) CSS modules or theme files │ └── ... │ ├── next.config.js # Next.js configuration file ├── tailwind.config.js # If you chose Tailwind ├── postcss.config.js # PostCSS setup (used with Tailwind) ├── package.json # Dependencies and scripts ├── package-lock.json # Locked dependencies ├── .gitignore # Git ignore rules └── README.md # Auto-generated docs
-
Run the command below to run your application locally:
cd my-nextjs-app npm run dev
Access http://localhost:3000 to view the homepage of your web app.
Build the app image and push it to Scaleway Container Registry
Before creating and pushing your image to the registry, make sure you have Created a Scaleway Container Registry namespace and logged into it.
-
Create a new
dockerfile
file at the root of your app folder, then add the following code to it:# Build the Next.js app FROM node:22-alpine WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build # Expose port and run server EXPOSE 3000 CMD ["npm", "start"]
-
Run the command below to build, tag, and push your image to the Scaleway Container registry:
docker build \ --platform linux/amd64 \ --push \ -t <CONTAINER_REGISTRY_ENDPOINT>/my-nextjs-app:latest .
Deploy your app using Serverless Containers
-
Deploy a Serverless Container with the following parameters:
- Registry: Scaleway Container Registry
- Registry namespace: the Container Registry namespace you pushed your image to.
- Container port:
3000
as it is the port exposed in the dockerfile. - Resources:
1000 mVCPU
and1024 MB
memory. - Autoscaling: set a minimum scale of
1
to avoid cold starts (optional).
The deployment of your container can take up to a minute to complete.
-
Once your container is ready, click the container endpoint from its Overview tab. Your web page displays, and is available to anyone with the link.
Going further
- You can deploy an already existing app by building its image and pushing it to the Scaleway Container registry as explained above.
- You can add a custom domain name to your website.
Visit our Help Center and find the answers to your most frequent questions.
Visit Help Center