You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- A Scaleway account logged into the [console](https://console.scaleway.com)
27
26
-[Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
28
27
- Installed [Docker](https://docs.docker.com/get-started/get-docker/) or [Docker Egine](https://docs.docker.com/engine/install/)
29
28
-[Created a Scaleway Container Registry namespace](/container-registry/how-to/create-namespace/) and [logged into it](/container-registry/how-to/connect-docker-cli/)
30
29
31
-
## Create and host a simple HTML static page
30
+
## Create and host a basic Next.js web application
31
+
32
+
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](/container-registry/), and deploy it to [Scaleway Serverless Containers](/serverless-containers/).
32
33
33
-
To host a static HTML page on Serverless Containers, you first need to create a simple HTML page that will serve as your website. Next, you will write a Dockerfile to containerize your application, specifying how your HTML file should be served. You will then build the container image locally, and push it to the [Scaleway Container Registry](/container-registry/), before deploying it to [Scaleway Serverless Containers](/serverless-containers/).
34
+
### Create your app and test it locally
34
35
35
36
1. In a terminal, run the command below to create a new folder and access it:
36
37
37
38
```bash
38
-
mkdir my-static-website
39
-
cd my-static-website
39
+
mkdir my-nextjs-app
40
+
cd my-nextjs-app
40
41
```
41
42
42
-
2.
43
+
2. 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](https://github.com/vercel/next.js/tree/canary/examples).
44
+
45
+
```bash
46
+
npx create-next-app@latest my-nextjs-app
47
+
```
43
48
49
+
3. 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:
44
50
51
+
```
52
+
my-nextjs-app/
53
+
├── app/ # Core: Routes using the App Router
54
+
│ ├── layout.tsx # Root layout (shared across pages)
55
+
│ ├── page.tsx # Homepage (http://localhost:3000)
56
+
│ └── globals.css # Global styles
57
+
│
58
+
├── public/ # Static assets (served at /)
59
+
│ ├── logo.svg
60
+
│ └── favicon.ico
61
+
│
62
+
├── components/ # (Optional) Your reusable components
63
+
│ └── ...
64
+
│
65
+
├── styles/ # (Optional) CSS modules or theme files
66
+
│ └── ...
67
+
│
68
+
├── next.config.js # Next.js configuration file
69
+
├── tailwind.config.js # If you chose Tailwind
70
+
├── postcss.config.js # PostCSS setup (used with Tailwind)
71
+
├── package.json # Dependencies and scripts
72
+
├── package-lock.json # Locked dependencies
73
+
├── .gitignore # Git ignore rules
74
+
└── README.md # Auto-generated docs
75
+
```
45
76
46
-
3. In the same folder, create a new `dockerfile` file and add the following code to it:
77
+
4. Run the command below to run your application locally:
78
+
79
+
```bash
80
+
cd my-nextjs-app
81
+
npm run dev
82
+
```
83
+
84
+
Access [http://localhost:3000](http://localhost:3000) to view the homepage of your web app.
85
+
86
+
### Build the app image and push it to Scaleway Container Registry
87
+
88
+
Before creating and pushing your image to the registry, make sure you have [Created a Scaleway Container Registry namespace](/container-registry/how-to/create-namespace/) and [logged into it](/container-registry/how-to/connect-docker-cli/).
89
+
90
+
1. Create a new `dockerfile` file at the root of your app folder, then add the following code to it:
47
91
48
92
```dockerfile
93
+
# Build the Next.js app
94
+
FROM node:18-alpine
95
+
WORKDIR /app
96
+
COPY package*.json ./
97
+
RUN npm install
98
+
COPY . .
99
+
RUN npm run build
100
+
101
+
# Expose port and run server
102
+
EXPOSE 3000
103
+
CMD ["npm", "start"]
49
104
```
50
105
51
-
4. Run the command below to build, tag, and push your image to the Scaleway Container registry:
106
+
2. Run the command below to build, tag, and push your image to the Scaleway Container registry:
You can find your Container Registry endpoint in the **Settings** tab of your Container Registry Endpoint in the [Scaleway console](https://console.scaleway.com/registry/namespaces)
62
117
</Message>
63
118
64
-
5.[Deploy a Serverless Container](/serverless-containers/how-to/deploy-container/) with the following parameters:
119
+
### Deploy your app using Serverless Containers
120
+
121
+
1.[Deploy a Serverless Container](/serverless-containers/how-to/deploy-container/) with the following parameters:
65
122
66
123
-**Registry**: Scaleway Container Registry
67
124
-**Registry namespace**: the Container Registry namespace you pushed your image to.
68
-
-**Container port**: `8O` as it is the [port](/serverless-containers/reference-content/port-parameter-variable/) exposed in the dockerfile.
69
-
-**Resources**: `100 mVCPU` and `256 MB` memory
125
+
-**Container port**: `3000` as it is the [port](/serverless-containers/reference-content/port-parameter-variable/) exposed in the dockerfile.
126
+
-**Resources**: `1000 mVCPU` and `1024 MB` memory
70
127
-**Autoscaling**: set a minimum scale of `1` to avoid [cold starts](/serverless-containers/concepts/#cold-start) (optional).
71
128
72
129
The deployment of your container can take up to a minute to complete.
73
130
74
-
6. 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.
131
+
2. 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.
75
132
76
133
## Going further
77
134
78
-
- You can host a website composed of multiple pages in the `my-static-website` folder.
135
+
- You can deploy an already existing app by building its image and pushing it to the Scaleway Container registry as explained above.
79
136
- You can [add a custom domain](/serverless-containers/how-to/add-a-custom-domain-to-a-container/) name to your website.
80
-
- You can host dynamic websites using dedicated frameworks for high-quality web applications.
0 commit comments