Skip to main content
Betadocs
DocsStatusSupportPricing
  • Introduction
    • Introduction to Webgune
    • How Webgune works
    • Creating an account
    • Creating your first project
    • Exploring the dashboard
  • Deployment

    • Deploying from GitHub
    • Deploying a Docker image
    • How builds work
    • Deployments and rollback
    • Environment variables
    • Custom start command
    • Health check
    • Database migrations

    Web apps

    • Web applications
      • Supported frameworks
      • Next.js
      • React / Vite
      • Node.js
      • Python
      • PHP
      • Go

    Bots & workers

    • Discord bots
    • Workers

    Docker

    • Docker
      • Writing a Dockerfile
      • Public Docker images

    Databases

    • Databases
      • PostgreSQL
      • MySQL
      • MariaDB
      • MongoDB
      • Redis

    Observability

    • Logs and monitoring
    • Web terminal

    Scaling

    • Availability and scaling
    • Persistent volumes
    • Backups and restore
    • Sleep mode

    Platform

    • One microVM per service
    • Network and isolation
    • Platform security
    • Deploying a template
      • Template catalog
    • Free subdomains
    • Custom domains
    • Buying a domain
    • Hosting DNS for a domain bought elsewhere
    • Managing your DNS records
    • SSL certificates
    • Redirects
    • Shared projects
      • Roles and permissions
    • Real-time collaboration
    • Continuous deployment
      • The kx712.yml file
    • VS Code extension
    • Plans and pricing
    • Payments and invoices
    • Account or per-project subscription
    • API reference
    • API keys
    • Webgune CLI
    • MCP server
    • JavaScript / TypeScript SDK
    • Support tickets
    • Status page
    • AI assistant
    • FAQ
    • Limits and resources
    • Account security
    • Best practices
    • Troubleshooting

Services / Docker

Writing a Dockerfile

Open as Markdown

This page gives Dockerfiles that work on Webgune, and the rules that keep images small and builds fast. To turn on the Dockerfile build, see Docker.

The rules

  1. Listen on $PORT and on 0.0.0.0.
  2. Build in several stages: build tools stay in the first one, the final image receives only the result.
  3. Copy dependency files before the code, so the install stays cached as long as dependencies do not change.
  4. Install from the lock file (npm ci, pip install -r, go mod download).
  5. Never copy a secret into the image. The service's variables are given to the container at runtime.
  6. Run the process in the foreground, as a non-root user when the base image provides one.
  7. Write logs to standard output.

Node.js

FROM node:22-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build && npm prune --omit=dev

FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build --chown=node:node /app/package.json ./
COPY --from=build --chown=node:node /app/node_modules ./node_modules
COPY --from=build --chown=node:node /app/dist ./dist
USER node
CMD ["node", "dist/server.js"]

npm prune --omit=dev removes development dependencies before the copy into the final image.

Standalone Next.js

With output: "standalone" in next.config:

FROM node:22-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
ARG NEXT_PUBLIC_API_URL
RUN npm run build

FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production HOSTNAME=0.0.0.0
COPY --from=build --chown=node:node /app/.next/standalone ./
COPY --from=build --chown=node:node /app/.next/static ./.next/static
COPY --from=build --chown=node:node /app/public ./public
USER node
CMD ["node", "server.js"]
  • HOSTNAME=0.0.0.0 is essential: without it, the Next.js standalone server listens on the machine name and cannot be reached.
  • .next/static and public must be copied next to server.js, otherwise CSS, JavaScript and images answer 404.
  • ARG NEXT_PUBLIC_API_URL picks up the service variable at build time (Docker).

With no particular need, auto build does exactly this (Next.js).

Static site with Nginx

FROM node:22-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM nginx:1.28-alpine
ENV PORT=80
COPY --from=build /app/dist /usr/share/nginx/html
COPY <<'EOF' /etc/nginx/templates/default.conf.template
server {
  listen ${PORT};
  root /usr/share/nginx/html;
  location / {
    try_files $uri $uri/ /index.html;
  }
}
EOF

The official Nginx image replaces ${PORT} at startup in the files of /etc/nginx/templates. The Static site nature of auto build produces the same image without a Dockerfile (React / Vite).

Python

FROM python:3.12-slim
WORKDIR /app
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN useradd --uid 1000 app && chown -R app /app
USER app
CMD ["sh", "-c", "gunicorn monprojet.wsgi:application --bind 0.0.0.0:${PORT:-8000} --workers 2"]

A -slim base (Debian) is the right choice for TensorFlow, PyTorch or opencv-python, which do not work on Alpine.

Go

FROM golang:1.24-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/server ./cmd/api

FROM alpine:3.21
RUN apk add --no-cache ca-certificates tzdata
COPY --from=build /out/server /server
USER 1000
CMD ["/server"]

ca-certificates is needed for outgoing HTTPS calls, tzdata for time zones.

Laravel with its assets

FROM node:22-alpine AS assets
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM php:8.3-cli-alpine
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
COPY --from=mlocati/php-extension-installer:2 /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions pdo_mysql pdo_pgsql intl zip bcmath gd opcache
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-scripts --no-autoloader --prefer-dist
COPY . .
COPY --from=assets /app/public/build ./public/build
RUN composer dump-autoload --optimize --no-dev
CMD ["sh", "-c", "php artisan config:cache && php artisan serve --host=0.0.0.0 --port=${PORT:-8000}"]

Auto build cannot build the Vite assets of a Laravel project. This Dockerfile does it in a first Node.js stage (PHP).

Subfolder of a monorepo

The Dockerfile stays at the repository root. It copies what the application needs:

FROM node:22-alpine AS build
WORKDIR /repo
COPY package.json package-lock.json ./
COPY apps/api/package.json apps/api/
COPY packages/shared/package.json packages/shared/
RUN npm ci
COPY . .
RUN npm run build --workspace apps/api

FROM node:22-alpine
WORKDIR /repo
COPY --from=build /repo ./
USER node
CMD ["node", "apps/api/dist/index.js"]

Make the application listen on $PORT

FormResult
CMD ["node", "server.js"]Correct if the code reads process.env.PORT
CMD ["sh", "-c", "app --port ${PORT:-8000}"]Correct: the shell replaces the variable
CMD ["app", "--port", "$PORT"]Incorrect: the application receives the text $PORT
CMD app --port 8000Correct only if the service's Container port is 8000

Checklist

ItemChecked
The application listens on 0.0.0.0:$PORT
The .dockerignore excludes .git, node_modules, .env
Dependency files are copied before the code
The final image contains neither a compiler nor needless sources
No secret in COPY, ENV or ARG
The process handles SIGTERM
Files to keep go on a volume

Test locally

docker build -t mon-app .
docker run --rm -e PORT=8080 -p 8080:8080 mon-app

If http://localhost:8080 answers, the image will behave the same way on Webgune, except that the build there has no access to your internal services.

Updated on November 20, 2026

DockerPreviousPublic Docker imagesNext

On this page

The rulesNode.jsStandalone Next.jsStatic site with NginxPythonGoLaravel with its assetsSubfolder of a monorepoMake the application listen on $PORTChecklistTest locally
© 2026 WebguneBack to the site