# Express Dockerfile Generator

URL: /dockerizer/express

Generate a production Dockerfile for an Express app — multi-stage, non-root, with dev dependencies pruned.

## Default configuration

- `appName` (App name): express — Used for the image tag, the compose service and the OCI labels.

- `port` (Port): 3000 — The port the app listens on inside the container. Keep it above 1024 so the process can bind it without root.

- `entrypoint` (Entry file): index.js — The file node runs on start, relative to the working directory.

- `compile` (TypeScript build step): false — Runs your `build` script in its own stage and ships the compiled output instead of the source.

- `nodeVersion` (Node version): 24 — Node 24 is the active LTS line. Node 20 goes end-of-life in April 2026.

- `packageManager` (Package manager): npm — pnpm and Yarn are installed through Corepack, which reads the `packageManager` field in your package.json.

- `baseVariant` (Base image): alpine — Alpine is the smallest. Debian slim is safest if you compile native modules such as sharp, canvas or bcrypt.

- `database` (Database service): none — Adds the database to docker-compose.yml with a healthcheck, a named volume and a DATABASE_URL wired into the app.

- `redis` (Redis service): false — Adds Redis to docker-compose.yml and exposes REDIS_URL to the app.

- `cacheMounts` (BuildKit cache mounts): true — Persists the package manager store between builds. Repeat builds skip the download entirely.

- `multiArch` (Multi-architecture build): false — Adds BUILDPLATFORM/TARGETARCH so `docker buildx build --platform linux/amd64,linux/arm64` cross-compiles natively.

- `healthcheck` (Healthcheck): true — Adds a HEALTHCHECK so orchestrators can restart an unresponsive container.

- `tini` (tini init): false — Runs the app under tini so signals and zombie processes are handled properly.

- `ociLabels` (OCI labels): false — Adds org.opencontainers.image.* metadata to the final image.

- `buildSecret` (Build secret mount): false — Reads a private registry token via --mount=type=secret so it never lands in an image layer.

## Generated files

### Dockerfile

Multi-stage build: dependencies, compilation and the runtime image are separate, so only what the app needs at runtime ships.

```docker
# syntax=docker/dockerfile:1
# Generated by Easypanel Dockerizer — https://easypanel.io/dockerizer

# --- Base ---------------------------------------------
FROM node:24-alpine AS base
WORKDIR /app

# --- Dependencies -------------------------------------
FROM base AS deps

# Manifests first: source changes must not bust the dependency cache
COPY package.json package-lock.json* ./
RUN --mount=type=cache,id=npm-store,target=/root/.npm,sharing=locked \
    npm ci --include=dev

# --- Production dependencies --------------------------

# Strips dev dependencies from the tree the runtime image copies
FROM deps AS prod-deps
RUN npm prune --omit=dev

# --- Runtime ------------------------------------------
FROM node:24-alpine AS runtime
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
COPY --from=prod-deps --chown=node:node /app/node_modules ./node_modules
COPY --chown=node:node . .
USER node
EXPOSE 3000
STOPSIGNAL SIGTERM

# Lets Docker, Compose and Easypanel see when the app is wedged
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD ["node", "-e", "fetch('http://127.0.0.1:3000/').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
CMD ["node", "index.js"]

```

### .dockerignore

Keeps the build context small and stops secrets and local dependencies from reaching an image layer.

```bash
# Version control
.git
.gitignore
.github

# Secrets — never bake these into an image layer
.env
.env.*
!.env.example
*.pem
*.key

# Editor and OS noise
.vscode
.idea
.DS_Store
Thumbs.db

# Docs and local tooling
README.md
LICENSE
docs
.editorconfig
docker-compose*.yml
Dockerfile*
.dockerignore

# Dependencies — reinstalled inside the image from the lockfile
node_modules
**/node_modules
.pnpm-store
.yarn/cache
.yarn/unplugged
npm-debug.log*
yarn-error.log*
pnpm-debug.log*

# Test and coverage output
coverage
.nyc_output
**/*.test.ts
**/*.spec.ts

```

### docker-compose.yml

Runs the image locally with its backing services, wired together and health-gated.

```yaml
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      NODE_ENV: production
      PORT: 3000

```

## Frequently asked questions

### Express binds to localhost and the container is unreachable. Why?

`app.listen(port)` inside a container must bind 0.0.0.0, not 127.0.0.1 — otherwise it only accepts connections from inside the container. Use `app.listen(port, '0.0.0.0')`.

## Related generators

- [Node.js](/dockerizer/nodejs)

- [Fastify](/dockerizer/fastify)

- [Hono](/dockerizer/hono)

- [NestJS](/dockerizer/nestjs)