Deploy a Next.js application
In this example, we are going to deploy an existing Next.js application into a customer's cloud and give that customer deployment its own HTTPS endpoint.
This is useful when the whole application—or a customer-facing part of it—needs to live with the customer's data, use services on their private network, or run under their cloud account. You keep the ordinary Next.js server and Dockerfile; Alien handles one deployment per environment.
Containers are useful when you already have a web server with a Dockerfile. You do not need to rewrite the application as a Worker or change how Next.js handles requests. Alien builds the image and runs it in each deployment.
A browser sends an HTTPS request to a Next.js Container running in the customer environment. The Container runs the application's existing Docker image and returns the response.
We will use alien.ts to point Alien at the Dockerfile, declare port 3000, and create the public endpoint. The rest of the project remains an ordinary Next.js application.
Describe the Container in alien.ts
const app = new alien.Container("app")
.code({
type: "source",
src: ".",
toolchain: { type: "docker", dockerfile: "Dockerfile" },
})
.cpu(0.5)
.memory("512Mi")
.port(3000)
.publicEndpoint("web", 3000, "http")
.environment({ PORT: "3000", HOSTNAME: "0.0.0.0" })
.permissions("app")
.build()Alien builds the Dockerfile, starts the container on port 3000, and creates the web endpoint.
publicEndpoint("web", 3000, "http") intentionally makes this application reachable over HTTPS. That is different from Commands, which can reach a named handler without publishing an application port.
Run Next.js normally
cd examples/nextjs-app
npm install
npm run devOpen http://localhost:3000 and http://localhost:3000/api/health first. When you are ready to deploy, run:
Deploy the same application
alien deploy production --platform aws # or gcp / azureAlien builds the included Dockerfile and prints the endpoint from the deployment.
To let a customer's admin create the deployment in their own environment, release the application and share its deployment link:
alien releasePublishes a version. Nothing is deployed for a customer yet.
alien onboard acme-corpCreates a deployment link for that customer.
The customer opens the link and deploys into their environment.
The customer receives their own HTTPS endpoint backed by the same Next.js image in their environment.
What you built
You took an ordinary containerized Next.js application and made it deployable into customer-owned infrastructure. Each customer receives an isolated application endpoint in their environment, ready to be linked to private databases and cloud services there. The application itself remains a normal Next.js server.
Source: examples/nextjs-app.
Next: Container, Networking and endpoints.