zeabur-service-exec

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Zeabur Service Exec

Zeabur Service Exec

Always use
npx zeabur@latest
to invoke Zeabur CLI.
Never use
zeabur
directly or any other installation method. If
npx
is not available, install Node.js first.
Run commands inside a running service container. Useful for debugging, inspecting files, checking env vars, testing connectivity, or running one-off database operations.
请始终使用
npx zeabur@latest
调用Zeabur CLI。
切勿直接使用
zeabur
或其他安装方式。如果没有
npx
,请先安装Node.js。
在运行中的服务容器内执行命令。适用于调试、检查文件、查看环境变量、测试网络连通性或执行一次性数据库操作。

Basic Usage

基本用法

Commands and arguments go after
--
:
bash
npx zeabur@latest service exec --id <service-id> -- <command> [args...]
命令及参数需放在
--
之后:
bash
npx zeabur@latest service exec --id <service-id> -- <command> [args...]

Database Operations

数据库操作

bash
undefined
bash
undefined

MongoDB - query, update, delete data

MongoDB - 查询、更新、删除数据

npx zeabur@latest service exec --id <mongodb-service-id> -- mongosh --eval 'db.users.find({})' npx zeabur@latest service exec --id <mongodb-service-id> -- mongosh --eval 'db.sessions.deleteMany({title: /test/i})'
npx zeabur@latest service exec --id <mongodb-service-id> -- mongosh --eval 'db.users.find({})' npx zeabur@latest service exec --id <mongodb-service-id> -- mongosh --eval 'db.sessions.deleteMany({title: /test/i})'

PostgreSQL - run SQL queries (PGPASSWORD is set automatically in Zeabur containers)

PostgreSQL - 执行SQL查询(Zeabur容器中会自动设置PGPASSWORD环境变量)

npx zeabur@latest service exec --id <pg-service-id> -- psql -U postgres -c 'SELECT * FROM users LIMIT 10;'
npx zeabur@latest service exec --id <pg-service-id> -- psql -U postgres -c 'SELECT * FROM users LIMIT 10;'

MySQL - run SQL queries (use env var to avoid interactive password prompt)

MySQL - 执行SQL查询(使用环境变量避免交互式密码提示)

npx zeabur@latest service exec --id <mysql-service-id> -- sh -c 'mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "SHOW DATABASES;"'
npx zeabur@latest service exec --id <mysql-service-id> -- sh -c 'mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "SHOW DATABASES;"'

Redis - run commands

Redis - 执行命令

npx zeabur@latest service exec --id <redis-service-id> -- redis-cli KEYS '*'
undefined
npx zeabur@latest service exec --id <redis-service-id> -- redis-cli KEYS '*'
undefined

Examples

示例

bash
undefined
bash
undefined

List files

列出文件

npx zeabur@latest service exec --id <service-id> -- ls -la
npx zeabur@latest service exec --id <service-id> -- ls -la

Check environment variables

检查环境变量

npx zeabur@latest service exec --id <service-id> -- env
npx zeabur@latest service exec --id <service-id> -- env

Check a specific env var

查看特定环境变量

npx zeabur@latest service exec --id <service-id> -- sh -c "echo $DATABASE_URL"
npx zeabur@latest service exec --id <service-id> -- sh -c "echo $DATABASE_URL"

Test database connectivity

测试数据库连通性

npx zeabur@latest service exec --id <service-id> -- sh -c "nc -zv postgres 5432"
npx zeabur@latest service exec --id <service-id> -- sh -c "nc -zv postgres 5432"

Check running processes

检查运行中的进程

npx zeabur@latest service exec --id <service-id> -- ps aux
npx zeabur@latest service exec --id <service-id> -- ps aux

Read a config file

读取配置文件

npx zeabur@latest service exec --id <service-id> -- cat /app/config.json
npx zeabur@latest service exec --id <service-id> -- cat /app/config.json

Check disk usage

检查磁盘使用情况

npx zeabur@latest service exec --id <service-id> -- df -h
undefined
npx zeabur@latest service exec --id <service-id> -- df -h
undefined

Flags

参数

FlagDescription
--id
Service ID
-n, --name
Service name (prefer
--id
)
--env-id
Environment ID (if multiple environments)
参数描述
--id
服务ID
-n, --name
服务名称(推荐使用
--id
--env-id
环境ID(当存在多个环境时使用)

Tips

提示

  • The
    --
    separator is required — everything after it is the command to run inside the container.
  • For compound commands, wrap in
    sh -c "..."
    .
  • Not all containers have a full shell —
    sh
    is more portable than
    bash
    .
  • Use single quotes outside and double quotes inside when dealing with variable expansion:
    sh -c "echo \$VAR"
    .
  • To find service IDs, use the
    zeabur-service-list
    skill. To check logs without exec, use the
    zeabur-deployment-logs
    skill. To manage env vars via CLI, use the
    zeabur-variables
    skill.
  • 必须使用
    --
    分隔符 —— 其后的所有内容均为要在容器内执行的命令。
  • 对于复合命令,请用
    sh -c "..."
    包裹。
  • 并非所有容器都具备完整的shell环境 ——
    sh
    bash
    更具可移植性。
  • 处理变量展开时,请在外部使用单引号,内部使用双引号:
    sh -c "echo \$VAR"
  • 如需查找服务ID,请使用
    zeabur-service-list
    技能。如需不通过exec查看日志,请使用
    zeabur-deployment-logs
    技能。如需通过CLI管理环境变量,请使用
    zeabur-variables
    技能。