Skip to content

Deploying a server app with a Dockerfile

A static site is built and uploaded; a server app runs a container. LeafCloud never writes a Dockerfile for you. If a repository needs a server and has no Dockerfile at its root, planning it from GitHub is refused with a fix pointing to this page.

  • The framework produces server output: Next.js without output: 'export', Nuxt SSR, SvelteKit with adapter-node, Remix, Astro with output: "server" or "hybrid".
  • Plain Node servers such as Express or Fastify, and servers written in Python, Go or another language.
  • Any other project that must run a process rather than upload a built folder.

If your framework can export a static site, use the static route instead — it needs no Dockerfile.

  • A Dockerfile at the repository root. Containerfile also works.
  • The process listens on all interfaces, 0.0.0.0, not only localhost.
  • It listens on the port you plan with: read $PORT when the app is configured to use the platform port, or state a fixed port in the Dockerfile and use that same port in the plan. EXPOSE is documentation; the plan’s port is what is routed.
  • A health path that returns a successful response, such as /healthz. The plan proposes /healthz; a simple HEALTHCHECK in the Dockerfile makes the expectation explicit. Keep that endpoint shallow: it should not call a database or any other service. A plain TCP check, which only needs the port to accept a connection, is the default when an app has no health path; see Health check.
server.jsjs
const express = require('express');
const app = express();
app.get('/healthz', (_req, res) => res.send('ok'));
app.listen(Number(process.env.PORT || 8080), '0.0.0.0');
Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
ENV PORT=8080
EXPOSE 8080
HEALTHCHECK CMD wget -q -O - http://localhost:8080/healthz || exit 1
CMD ["node", "server.js"]
next.config.mjsjs
export default { output: 'standalone' };
Dockerfile
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine
WORKDIR /app
ENV NODE_ENV=production PORT=3000 HOSTNAME=0.0.0.0
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
COPY --from=build /app/public ./public
EXPOSE 3000
HEALTHCHECK CMD wget -q -O - http://localhost:3000/healthz || exit 1
CMD ["node", "server.js"]

Add a app/api/healthz/route.ts (or your framework’s health route) that returns 200.

astro.config.mjsjs
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
export default defineConfig({
output: 'server',
adapter: node({ mode: 'standalone' }),
});
Dockerfile
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine
WORKDIR /app
ENV NODE_ENV=production PORT=4321 HOST=0.0.0.0
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY --from=build /app/package.json ./package.json
EXPOSE 4321
HEALTHCHECK CMD wget -q -O - http://localhost:4321/healthz || exit 1
CMD ["node", "./dist/server/entry.mjs"]

Commit the Dockerfile, then plan the repository again from the dashboard. The setup pull request adds only the deploy workflow; your Dockerfile stays in your repository.