Deploy a Node.js app with Docker
Updated
If your Node.js app runs with npm start, it is one Dockerfile away from a public HTTPS URL. Below
are Dockerfiles for a plain Express server and for Next.js, then the single command that deploys either.
Express
# Dockerfile
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
ENV NODE_ENV=production
EXPOSE 3000
CMD ["node", "server.js"]
Make sure the server listens on all interfaces: app.listen(3000) does by default, but
app.listen(3000, "localhost") would be unreachable from outside the container.
Next.js
Set output: "standalone" in next.config.js; Next.js then produces a small self-contained
server, and the image stays lean:
# Dockerfile
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production HOSTNAME=0.0.0.0 PORT=3000
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
COPY --from=build /app/public ./public
EXPOSE 3000
CMD ["node", "server.js"]
HOSTNAME=0.0.0.0 is the line people miss: without it the standalone server only listens inside the container.
Deploy
Copy the push command from your Dashboard and add the port plus any environment variables as tags:
docker buildx build --platform linux/amd64 \
-t push.to.appi.sh/<your-push-id>/app:port_3000 \
-t push.to.appi.sh/<your-push-id>/app:env_LOG_LEVEL___info \
--push .
Values with characters Docker tags don't allow (URLs, API keys with / or =) go in an
env64_ tag, base64url-encoded — see the docs. Keep
--platform linux/amd64 even on an Apple Silicon Mac.
Environment variables at build time
Tags set variables when the container starts. Next.js inlines NEXT_PUBLIC_* variables
during npm run build, so those must be present at build time, for example with
ARG/ENV lines in the build stage.