Lzh on GitHub

Docker

使用 Docker 部署你的 Content 应用。

Docker 是一个流行的容器化平台,它允许你将你的应用程序及其所有依赖项打包到一个单独的容器中。这使得在任何支持 Docker 的平台上部署你的 Content 应用变得容易。

使用 Node.js 镜像

使用 Docker 的 Node.js 镜像,你可以部署你的 Content 应用。你只需要创建一个 Dockerfile 并构建镜像。这是一个示例 Dockerfile:

Dockerfile
# Build Stage 1

FROM node:22-alpine AS build
WORKDIR /app

RUN corepack enable

# Copy package.json and your lockfile, here we add pnpm-lock.yaml for illustration
COPY package.json pnpm-lock.yaml .npmrc ./

# Install dependencies
RUN pnpm i

# Copy the entire project
COPY . ./

# Build the project
RUN pnpm run build

# Build Stage 2

FROM node:22-alpine
WORKDIR /app

# Only `.output` folder is needed from the build stage
COPY --from=build /app/.output/ ./

# Change the port and host
ENV PORT 80
ENV HOST 0.0.0.0

EXPOSE 80

CMD ["node", "/app/server/index.mjs"]

使用 Bun 镜像

如果你喜欢使用 Bun,可以使用官方的 Bun 镜像。这是一个示例 Dockerfile:

Dockerfile
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 AS build
WORKDIR /app

COPY package.json bun.lockb ./

# use ignore-scripts to avoid builting node modules like better-sqlite3
RUN bun install --frozen-lockfile --ignore-scripts

# Copy the entire project
COPY . .

RUN bun --bun run build

# copy production dependencies and source code into final image
FROM oven/bun:1 AS production
WORKDIR /app

# Only `.output` folder is needed from the build stage
COPY --from=build /app/.output /app

# run the app
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "--bun", "run", "/app/server/index.mjs" ]