zeabur-dockerfile
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseZeabur Dockerfile Generation
Zeabur Dockerfile 生成
Always useto invoke Zeabur CLI. Never usenpx zeabur@latestdirectly or any other installation method. Ifzeaburis not available, install Node.js first.npx
When deploying source code to Zeabur, you must generate a Dockerfile. This skill covers how to analyze a project and produce a correct, deployable Dockerfile.
请始终使用调用Zeabur CLI。 切勿直接使用npx zeabur@latest或其他安装方式。如果没有zeabur,请先安装Node.js。npx
将源代码部署到Zeabur时,必须生成Dockerfile。本技能涵盖如何分析项目并生成正确的、可部署的Dockerfile。
Prerequisites
前置条件
Before generating a Dockerfile, read the key project files:
| Language | Files to read |
|---|---|
| Node.js | |
| Python | |
| Go | |
| Rust | |
| PHP | |
| Ruby | |
| Java | |
| .NET | |
| Elixir | |
Also check for:
- Existing or
Dockerfiledocker-compose.yml - Build config (,
vite.config.js,webpack.config.js, etc.)next.config.js - for required environment variables
.env.example
What NOT to read — skip these to save tokens:
- HTML files — static assets, never affect deployment logic
- Lockfile contents — only check which lockfile exists (to determine package manager). Do NOT parse the contents.
- Markdown files — documentation only, never influences Dockerfile decisions
生成Dockerfile前,请读取项目的关键文件:
| 编程语言 | 需要读取的文件 |
|---|---|
| Node.js | |
| Python | |
| Go | |
| Rust | |
| PHP | |
| Ruby | |
| Java | |
| .NET | |
| Elixir | |
同时检查以下内容:
- 已存在的 或
Dockerfiledocker-compose.yml - 构建配置文件(、
vite.config.js、webpack.config.js等)next.config.js - 中的必填环境变量
.env.example
无需读取的内容 — 跳过这些以节省令牌:
- HTML文件 — 静态资源,绝不影响部署逻辑
- 锁文件内容 — 仅需检查存在哪种锁文件(以确定包管理器),无需解析内容
- Markdown文件 — 仅为文档,绝不影响Dockerfile的决策
Workflow
工作流程
1. Analyze the Project
1. 分析项目
From the prerequisite files, determine:
- Programming language and version
- Framework (if any)
- Package manager
- Build command
- Start command
- Port the app listens on
- Static site vs server-side app
从前置文件中确定:
- 编程语言及版本
- 框架(如有)
- 包管理器
- 构建命令
- 启动命令
- 应用监听的端口
- 静态站点还是服务端应用
2. Generate the Dockerfile
2. 生成Dockerfile
General Rules
通用规则
- No comments in the Dockerfile
- No or
ENVinstructions (unless required by the framework — see language-specific sections)ARG - Add — possible values:
LABEL "language"="<lang>",nodejs,python,go,static,ruby,java,php,rust,dotnet,elixir,swiftbun - Add only for actual web frameworks (see list below)
LABEL "framework"="<framework>" - Always before running any install/build commands
COPY . . - Set unless the user specifies otherwise
WORKDIR /src - Add for the port the app listens on
EXPOSE - Do not use multi-stage builds unless the build image differs from the runtime image (e.g., build with Node.js, serve with )
zeabur/caddy-static
- Dockerfile中不添加注释
- 不使用 或
ENV指令(除非框架要求——见各语言特定章节)ARG - 添加 — 可选值:
LABEL "language"="<lang>"、nodejs、python、go、static、ruby、java、php、rust、dotnet、elixir、swiftbun - 仅为实际Web框架添加 (见下方列表)
LABEL "framework"="<framework>" - 在运行任何安装/构建命令前始终执行
COPY . . - 除非用户另有指定,否则设置
WORKDIR /src - 为应用监听的端口添加 指令
EXPOSE - 除非构建镜像与运行时镜像不同(例如用Node.js构建,用 提供服务),否则不使用多阶段构建
zeabur/caddy-static
Framework vs Package — Only These Get a Framework Label
框架与包的区分 — 仅以下内容可标记为框架
Frameworks (use ):
, , , , , , , , , , , , , , , , , , , , , , , , , ,
LABEL "framework"="..."vitecreate-react-appnext.jsremixnuxt.jsuminest.jshexovitepressastrosli.devdocusaurusnitropackhonomedusasvelteflaskdjangofastapispring-bootlaravelthinkphprailsaspnetblazorwasmelysiabaojsNever label as framework (these are packages/libraries):
- Python: gradio, pandas, numpy, requests, matplotlib, scikit-learn, tensorflow, pytorch, opencv, pillow, beautifulsoup4, selenium
- Node.js: express, koa, hapi, fastify, socket.io, moment, lodash, axios
- Other: bootstrap, jquery, chart.js, three.js, d3.js
If unsure whether something is a framework or package, do NOT add the framework label.
框架(使用 ):
、、、、、、、、、、、、、、、、、、、、、、、、、、
LABEL "framework"="..."vitecreate-react-appnext.jsremixnuxt.jsuminest.jshexovitepressastrosli.devdocusaurusnitropackhonomedusasvelteflaskdjangofastapispring-bootlaravelthinkphprailsaspnetblazorwasmelysiabaojs绝不能标记为框架(这些是包/库):
- Python: gradio、pandas、numpy、requests、matplotlib、scikit-learn、tensorflow、pytorch、opencv、pillow、beautifulsoup4、selenium
- Node.js: express、koa、hapi、fastify、socket.io、moment、lodash、axios
- 其他: bootstrap、jquery、chart.js、three.js、d3.js
若不确定某内容是框架还是包,请不要添加框架标签。
Static Sites — zeabur/caddy-static
zeabur/caddy-static静态站点 — 使用 zeabur/caddy-static
zeabur/caddy-staticFor pure static websites (Vite, Astro static, Docusaurus, plain HTML), use :
zeabur/caddy-staticdockerfile
FROM node:22-slim AS build
LABEL "language"="nodejs"
LABEL "framework"="vite"
WORKDIR /src
COPY . .
RUN npm install
RUN npm run build
FROM zeabur/caddy-static
COPY /src/dist /usr/share/caddyRules for :
zeabur/caddy-static- Copy build output to
/usr/share/caddy - Do NOT add or
CMD— the image handles itENTRYPOINT - It listens on port
8080 - Only use for truly static sites. Do NOT use for SSR frameworks (Next.js, Nuxt.js, SvelteKit, etc.)
- If building with Node.js then serving as static, set (not
LABEL "language"="nodejs")"static"
对于纯静态网站(Vite、Astro静态版、Docusaurus、纯HTML),使用 :
zeabur/caddy-staticdockerfile
FROM node:22-slim AS build
LABEL "language"="nodejs"
LABEL "framework"="vite"
WORKDIR /src
COPY . .
RUN npm install
RUN npm run build
FROM zeabur/caddy-static
COPY /src/dist /usr/share/caddyzeabur/caddy-static- 将构建产物复制到
/usr/share/caddy - 不要添加 或
CMD— 镜像会自动处理ENTRYPOINT - 监听端口为
8080 - 仅用于真正的静态站点,不要用于SSR框架(Next.js、Nuxt.js、SvelteKit等)
- 若用Node.js构建后以静态方式提供服务,请设置 (而非
LABEL "language"="nodejs")"static"
Node.js
Node.js
- Default base image:
node:22-slim - Determine package manager by lockfile presence:
| Lockfile | Package manager | Install command |
|---|---|---|
| npm | |
| yarn | |
| pnpm | |
- When using , use
npm. Do NOT usenpm installor flags likenpm ci,--only=production,--omit=dev.--frozen-lockfile - For Vite static sites (React, Vue static builds), use to serve.
zeabur/caddy-static - For Vite with SSR frameworks (SvelteKit), use Node.js runtime.
Next.js — Zeabur injects into the container, so Next.js production mode listens on 8080 by default. No extra config needed.
PORT=8080dockerfile
FROM node:22-slim
LABEL "language"="nodejs"
LABEL "framework"="next.js"
WORKDIR /src
COPY . .
RUN npm install
RUN npm run build
EXPOSE 8080
CMD ["npm", "start"]Svelte / SvelteKit — Use (not alpine, not slim). Set . Single-stage build — do NOT use . Do NOT use or adapter-specific build commands.
node:22ENV PORT=8080zeabur/caddy-staticcross-env ADAPTER=staticdockerfile
FROM node:22
LABEL "language"="nodejs"
LABEL "framework"="svelte"
ENV PORT=8080
WORKDIR /src
RUN npm install -g pnpm@9
COPY . .
RUN pnpm install
RUN pnpm build
EXPOSE 8080
CMD ["pnpm", "start"]- 默认基础镜像:
node:22-slim - 根据锁文件的存在确定包管理器:
| 锁文件 | 包管理器 | 安装命令 |
|---|---|---|
| npm | |
| yarn | |
| pnpm | |
- 使用npm时,执行 ,不要使用
npm install或npm ci、--only=production、--omit=dev等参数--frozen-lockfile - 对于Vite静态站点(React、Vue静态构建),使用 提供服务
zeabur/caddy-static - 对于带SSR框架的Vite(如SvelteKit),使用Node.js运行时
Next.js — Zeabur会将 注入容器,因此Next.js生产模式默认监听8080端口,无需额外配置。
PORT=8080dockerfile
FROM node:22-slim
LABEL "language"="nodejs"
LABEL "framework"="next.js"
WORKDIR /src
COPY . .
RUN npm install
RUN npm run build
EXPOSE 8080
CMD ["npm", "start"]Svelte / SvelteKit — 使用 (不要用alpine或slim),设置 ,采用单阶段构建——不要使用 ,不要使用 或特定适配器的构建命令。
node:22ENV PORT=8080zeabur/caddy-staticcross-env ADAPTER=staticdockerfile
FROM node:22
LABEL "language"="nodejs"
LABEL "framework"="svelte"
ENV PORT=8080
WORKDIR /src
RUN npm install -g pnpm@9
COPY . .
RUN pnpm install
RUN pnpm build
EXPOSE 8080
CMD ["pnpm", "start"]Python
Python
- Default base image:
python:3.10
Flask — Find the WSGI entry first. For example, if contains , the entry is .
main.pyapp = Flask(__name__)main:appdockerfile
FROM python:3.10
LABEL "language"="python"
LABEL "framework"="flask"
WORKDIR /src
COPY . .
RUN pip install -r requirements.txt gunicorn
EXPOSE 8080
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "main:app"]FastAPI — Choose the start method based on what exists:
- If is in
fastapi-cli→requirements.txtfastapi run - If exists in a
if __name__ == "__main__":file →.pypython <file>.py - Otherwise → (install
uvicorn main:app --host 0.0.0.0 --port 8080if missing)uvicorn
dockerfile
FROM python:3.10
LABEL "language"="python"
LABEL "framework"="fastapi"
WORKDIR /src
COPY . .
RUN pip install -r requirements.txt
EXPOSE 8080
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]Generic Python — If WSGI might be applicable, use . If unsure, just use .
gunicornpython <file>.py- 默认基础镜像:
python:3.10
Flask — 先找到WSGI入口。例如,若 包含 ,则入口为 。
main.pyapp = Flask(__name__)main:appdockerfile
FROM python:3.10
LABEL "language"="python"
LABEL "framework"="flask"
WORKDIR /src
COPY . .
RUN pip install -r requirements.txt gunicorn
EXPOSE 8080
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "main:app"]FastAPI — 根据现有内容选择启动方式:
- 若 中包含
requirements.txt→ 使用fastapi-clifastapi run - 若某 文件中存在
.py→ 使用if __name__ == "__main__":python <file>.py - 其他情况 → 使用 (若缺失则安装
uvicorn main:app --host 0.0.0.0 --port 8080)uvicorn
dockerfile
FROM python:3.10
LABEL "language"="python"
LABEL "framework"="fastapi"
WORKDIR /src
COPY . .
RUN pip install -r requirements.txt
EXPOSE 8080
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]通用Python — 若适用WSGI,使用 ;若不确定,直接使用 。
gunicornpython <file>.pyGo
Go
dockerfile
FROM golang:1.23 AS build
WORKDIR /src
COPY . .
RUN go build -o /app .
FROM debian:bookworm-slim
LABEL "language"="go"
COPY /app /app
EXPOSE 8080
CMD ["/app"]dockerfile
FROM golang:1.23 AS build
WORKDIR /src
COPY . .
RUN go build -o /app .
FROM debian:bookworm-slim
LABEL "language"="go"
COPY /app /app
EXPOSE 8080
CMD ["/app"]PHP (Laravel / Symfony / Generic)
PHP(Laravel / Symfony / 通用)
Uses NGINX + PHP-FPM. Adjust PHP version and extensions as needed.
dockerfile
FROM php:8.3-fpm
LABEL "language"="php"
WORKDIR /var/www
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync
RUN apt update && apt install -y cron curl gettext git grep libicu-dev nginx pkg-config unzip && rm -rf /var/lib/apt/lists/*
RUN install-php-extensions @composer apcu bcmath gd intl mysqli opcache pcntl pdo_mysql sysvsem zip
RUN cat <<'NGINX' > /etc/nginx/sites-enabled/default
server {
listen 8080;
root /var/www;
index index.php index.html;
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ /\.(?!well-known).* { deny all; }
error_log /dev/stderr;
access_log /dev/stderr;
}
NGINX
RUN chown -R www-data:www-data /var/www
COPY . /var/www
USER www-data
RUN if [ -f composer.json ]; then composer install --optimize-autoloader --classmap-authoritative --no-dev; fi && if [ -f package.json ]; then npm install; fi
USER root
EXPOSE 8080
CMD ["sh", "-c", "php-fpm -D && nginx -g 'daemon off;'"]For Laravel, add optimization after :
composer installdockerfile
RUN php artisan config:cache && php artisan route:cache && php artisan view:cache使用NGINX + PHP-FPM,根据需要调整PHP版本和扩展。
dockerfile
FROM php:8.3-fpm
LABEL "language"="php"
WORKDIR /var/www
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && sync
RUN apt update && apt install -y cron curl gettext git grep libicu-dev nginx pkg-config unzip && rm -rf /var/lib/apt/lists/*
RUN install-php-extensions @composer apcu bcmath gd intl mysqli opcache pcntl pdo_mysql sysvsem zip
RUN cat <<'NGINX' > /etc/nginx/sites-enabled/default
server {
listen 8080;
root /var/www;
index index.php index.html;
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ /\.(?!well-known).* { deny all; }
error_log /dev/stderr;
access_log /dev/stderr;
}
NGINX
RUN chown -R www-data:www-data /var/www
COPY . /var/www
USER www-data
RUN if [ -f composer.json ]; then composer install --optimize-autoloader --classmap-authoritative --no-dev; fi && if [ -f package.json ]; then npm install; fi
USER root
EXPOSE 8080
CMD ["sh", "-c", "php-fpm -D && nginx -g 'daemon off;'"]对于Laravel,在 后添加优化步骤:
composer installdockerfile
RUN php artisan config:cache && php artisan route:cache && php artisan view:cache3. Handle Existing Dockerfiles
3. 处理已存在的Dockerfile
- Analyze the existing Dockerfile first
- Use it as-is if it looks correct
- Suggest improvements only if there are issues (wrong port, missing dependencies, etc.)
- Always add Zeabur-specific labels (,
language) if missingframework
- 先分析已有的Dockerfile
- 如果看起来正确则直接使用
- 仅当存在问题(端口错误、依赖缺失等)时建议改进
- 如果缺少Zeabur特定标签(、
language),请务必添加framework
CLI Commands
CLI命令
After generating the Dockerfile, deploy with:
bash
npx zeabur@latest deploy --project-id <project-id> --jsonFor redeployment (must pass service ID to avoid creating duplicates):
bash
npx zeabur@latest deploy --project-id <project-id> --service-id <service-id> --jsonUse the skill for the full deployment workflow.
zeabur-deploy生成Dockerfile后,使用以下命令部署:
bash
npx zeabur@latest deploy --project-id <project-id> --json重新部署时(必须传入服务ID以避免创建重复服务):
bash
npx zeabur@latest deploy --project-id <project-id> --service-id <service-id> --json完整部署流程请使用 技能。
zeabur-deployError Handling
错误处理
If the build or runtime fails:
- Check build logs with the skill
zeabur-deployment-logs - Common issues:
- Missing dependencies — add to install step
RUN - Wrong port — verify matches what the app listens on; check with
EXPOSEskillzeabur-port-mismatch - Wrong start command — verify matches the project's actual entry point
CMD - Static site served as SSR — switch to if the app produces static output
zeabur/caddy-static - SSR served as static — switch to Node.js runtime if the app requires a server
- Missing dependencies — add to
- Fix the Dockerfile, then redeploy with to update the existing service
--service-id
如果构建或运行失败:
- 使用 技能查看构建日志
zeabur-deployment-logs - 常见问题:
- 依赖缺失 — 在 安装步骤中添加缺失的依赖
RUN - 端口错误 — 验证 与应用监听的端口是否匹配;使用
EXPOSE技能排查zeabur-port-mismatch - 启动命令错误 — 验证 与项目实际入口是否一致
CMD - 静态站点被当作SSR部署 — 如果应用生成静态产物,切换为
zeabur/caddy-static - SSR被当作静态站点部署 — 如果应用需要服务器,切换为Node.js运行时
- 依赖缺失 — 在
- 修复Dockerfile后,使用 参数重新部署以更新现有服务
--service-id