zeabur-service-exec
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseZeabur Service Exec
Zeabur Service Exec
Always useto invoke Zeabur CLI. Never usenpx zeabur@latestdirectly or any other installation method. Ifzeaburis not available, install Node.js first.npx
Run commands inside a running service container. Useful for debugging, inspecting files, checking env vars, testing connectivity, or running one-off database operations.
请始终使用调用Zeabur CLI。 切勿直接使用npx zeabur@latest或其他安装方式。如果没有zeabur,请先安装Node.js。npx
在运行中的服务容器内执行命令。适用于调试、检查文件、查看环境变量、测试网络连通性或执行一次性数据库操作。
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
undefinedbash
undefinedMongoDB - 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 '*'
undefinednpx zeabur@latest service exec --id <redis-service-id> -- redis-cli KEYS '*'
undefinedExamples
示例
bash
undefinedbash
undefinedList 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
undefinednpx zeabur@latest service exec --id <service-id> -- df -h
undefinedFlags
参数
| Flag | Description |
|---|---|
| Service ID |
| Service name (prefer |
| Environment ID (if multiple environments) |
| 参数 | 描述 |
|---|---|
| 服务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 — is more portable than
sh.bash - Use single quotes outside and double quotes inside when dealing with variable expansion: .
sh -c "echo \$VAR" - To find service IDs, use the skill. To check logs without exec, use the
zeabur-service-listskill. To manage env vars via CLI, use thezeabur-deployment-logsskill.zeabur-variables
- 必须使用 分隔符 —— 其后的所有内容均为要在容器内执行的命令。
-- - 对于复合命令,请用 包裹。
sh -c "..." - 并非所有容器都具备完整的shell环境 —— 比
sh更具可移植性。bash - 处理变量展开时,请在外部使用单引号,内部使用双引号:。
sh -c "echo \$VAR" - 如需查找服务ID,请使用 技能。如需不通过exec查看日志,请使用
zeabur-service-list技能。如需通过CLI管理环境变量,请使用zeabur-deployment-logs技能。zeabur-variables