ddev
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDDEV
DDEV
DDEV is a Docker-based local development tool for PHP/Node projects. It wraps common CLI tools (composer, npm, wp, drush, etc.) so they run inside containers without requiring local installation. Full docs: https://docs.ddev.com
DDEV是一款基于Docker的PHP/Node项目本地开发工具。它封装了常见的CLI工具(composer、npm、wp、drush等),无需本地安装即可在容器内运行。完整文档:https://docs.ddev.com
CLI Syntactic Sugar
CLI语法糖
DDEV provides shortcut commands that proxy to container-internal tools. Use these instead of :
ddev execddev composer install # runs composer inside the container
ddev npm run build # runs npm inside the container
ddev wp plugin list # runs wp-cli (WordPress only)
ddev drush cr # runs drush (Drupal only)
ddev artisan migrate # runs artisan (Laravel only)
ddev console cache:clear # runs bin/console (Symfony only)
ddev yarn add <pkg> # runs yarn inside the container
ddev php -v # runs PHP inside the containerFor the full list of shortcuts and their mappings, run .
ddev helpDDEV提供了代理到容器内部工具的快捷命令。请使用这些命令替代:
ddev execddev composer install # 在容器内运行composer
ddev npm run build # 在容器内运行npm
ddev wp plugin list # 运行wp-cli(仅适用于WordPress)
ddev drush cr # 运行drush(仅适用于Drupal)
ddev artisan migrate # 运行artisan(仅适用于Laravel)
ddev console cache:clear # 运行bin/console(仅适用于Symfony)
ddev yarn add <pkg> # 在容器内运行yarn
ddev php -v # 在容器内运行PHP如需查看完整的快捷命令及其映射关系,请运行。
ddev helpDDEV Commands Work from Any Subdirectory
DDEV命令可在任意子目录执行
DDEV automatically detects its project root from any subdirectory within the project tree. Most DDEV commands work out of the box regardless of where the shell is located:
bash
ddev wp plugin list
ddev mailpit
ddev db
ddev composer show
ddev npm ls
ddev drush cr
ddev start
ddev describe
ddev sshNo special flags or path resolution is needed for these commands.
DDEV可自动从项目目录树中的任意子目录检测项目根目录。大多数DDEV命令无需额外配置,无论当前shell处于哪个目录都能直接运行:
bash
ddev wp plugin list
ddev mailpit
ddev db
ddev composer show
ddev npm ls
ddev drush cr
ddev start
ddev describe
ddev ssh这些命令不需要特殊标志或路径解析。
When --dir
Scoping IS Required
--dir何时需要使用--dir
指定目录
--dirThe flag is only needed when running file-path-sensitive scripts via that must target a specific subdirectory inside the container. This applies when the command operates on files relative to the working directory (e.g., reading a specific , or reading a specific ).
--dirddev execcomposer installcomposer.jsonnpm installpackage.json只有当通过运行对文件路径敏感的脚本,且必须指向容器内特定子目录时,才需要使用标志。例如,命令需要读取相对工作目录的文件(如读取特定的,或读取特定的)时。
ddev exec--dircomposer installcomposer.jsonnpm installpackage.jsonStep 1: Resolve the container path
步骤1:解析容器路径
Run the bundled resolve script to map the host subdirectory to a container path:
bash
scripts/resolve-ddev-root.sh "$(pwd)"Output (JSON):
json
{
"project_root": "/Users/you/Projects/mysite",
"container_path": "/var/www/html/wp-content/plugins/my-plugin",
"relative_path": "wp-content/plugins/my-plugin",
"project_name": "mysite"
}- empty -- working directory is the DDEV root, no
relative_pathneeded.--dir - non-empty -- use
relative_pathwith the--dirvalue for file-path-sensitive commands.container_path
运行内置的解析脚本,将主机子目录映射到容器路径:
bash
scripts/resolve-ddev-root.sh "$(pwd)"输出(JSON格式):
json
{
"project_root": "/Users/you/Projects/mysite",
"container_path": "/var/www/html/wp-content/plugins/my-plugin",
"relative_path": "wp-content/plugins/my-plugin",
"project_name": "mysite"
}- 若为空——当前工作目录即为DDEV根目录,无需使用
relative_path。--dir - 若非空——请将
relative_path的值与container_path配合使用,以运行对文件路径敏感的命令。--dir
Step 2: Execute the scoped command
步骤2:执行指定目录的命令
If DDEV is not running, start it first with .
ddev startbash
undefined如果DDEV未运行,请先执行启动它。
ddev startbash
undefinedInstall dependencies scoped to a plugin subdirectory
针对插件子目录安装依赖
ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "composer install"
ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "npm install"
ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "composer install"
ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "npm install"
Run a script that reads files relative to the working directory
运行读取相对工作目录文件的脚本
ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "phpunit"
Without `--dir`, these commands run at the container docroot (`/var/www/html`) and operate on the wrong `composer.json`, `package.json`, or project context.ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "phpunit"
如果不使用`--dir`,这些命令会在容器的文档根目录(`/var/www/html`)运行,操作的是错误的`composer.json`、`package.json`或项目上下文。Running Commands in Containers
在容器内运行命令
Use when no shortcut exists or when you need to target a specific container directory:
ddev execbash
undefined当没有快捷命令可用,或需要指向容器内特定目录时,请使用:
ddev execbash
undefinedRuns in web container at docroot
在web容器的文档根目录运行
ddev exec ls -la
ddev exec ls -la
Scope to a subdirectory for file-path-sensitive operations
针对子目录运行对文件路径敏感的操作
ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "composer install"
ddev exec --dir="/var/www/html/wp-content/plugins/my-plugin" bash -c "composer install"
Run in the database container
在数据库容器内运行
ddev exec -s db mysql -e "SHOW DATABASES"
ddev exec -s db mysql -e "SHOW DATABASES"
Shorthand alias
简写别名
ddev . ls -la
undefinedddev . ls -la
undefinedSubpath Mapping (for ddev exec --dir
)
ddev exec --dir子路径映射(适用于ddev exec --dir
)
ddev exec --dirPath resolution is only needed when using to scope file-path-sensitive scripts to a subdirectory. Standard DDEV commands (, , , , etc.) do not require this -- they work from any subdirectory automatically.
ddev exec --dirddev wpddev mailpitddev dbddev start只有在使用将对文件路径敏感的脚本限定到子目录时,才需要进行路径解析。标准DDEV命令(如、、、等)无需此操作——它们可自动在任意子目录运行。
ddev exec --dirddev wpddev mailpitddev dbddev startResolving the DDEV Root
解析DDEV根目录
Use the bundled resolve script to find the DDEV project root and compute the container path:
bash
undefined使用内置的解析脚本查找DDEV项目根目录并计算容器路径:
bash
undefinedFrom any subdirectory within a DDEV project
在DDEV项目内的任意子目录执行
scripts/resolve-ddev-root.sh /path/to/wp-content/plugins/my-plugin
The script walks up the directory tree looking for `.ddev/config.yaml`. If no argument is provided, it uses the current working directory.scripts/resolve-ddev-root.sh /path/to/wp-content/plugins/my-plugin
该脚本会遍历目录树寻找`.ddev/config.yaml`文件。如果未提供参数,则使用当前工作目录。Manual Path Computation
手动计算路径
If the script is unavailable, compute the path manually:
- Find the directory containing (the DDEV project root)
.ddev/config.yaml - Compute the relative path from that root to the current working directory
- Prepend to get the container path
/var/www/html/
如果脚本不可用,可手动计算路径:
- 找到包含的目录(即DDEV项目根目录)
.ddev/config.yaml - 计算从该根目录到当前工作目录的相对路径
- 在相对路径前添加,即可得到容器路径
/var/www/html/
Project Information
项目信息
Use to get detailed information about the current DDEV project. Add the flag to get structured JSON output:
ddev describe-jbash
ddev describe -jThis provides useful details such as:
- Project type (wordpress, drupal, laravel, etc.)
- Primary URL and all project URLs
- PHP version and Node.js version
- Database type and version (mariadb, mysql, postgres)
- Web server type (nginx-fpm, apache-fpm)
- Service status for web, db, and additional services
- Published ports for host-to-container mapping
Example JSON output fields:
- - Project type (wordpress, drupal, etc.)
type - - Main project URL
primary_url - - Array of all project URLs (HTTP and HTTPS)
urls - - PHP version in use
php_version - - Node.js version in use
nodejs_version - - Database type (mariadb, mysql, postgres)
database_type - - Web server (nginx-fpm, apache-fpm)
webserver_type - - Status and details for each service
services
使用获取当前DDEV项目的详细信息。添加标志可获取结构化JSON输出:
ddev describe-jbash
ddev describe -j该命令会提供以下有用信息:
- 项目类型(wordpress、drupal、laravel等)
- 主URL及所有项目URL
- PHP版本和Node.js版本
- 数据库类型和版本(mariadb、mysql、postgres)
- Web服务器类型(nginx-fpm、apache-fpm)
- 服务状态(web、db及其他附加服务)
- 发布端口(主机到容器的端口映射)
示例JSON输出字段:
- - 项目类型(wordpress、drupal等)
type - - 项目主URL
primary_url - - 所有项目URL数组(HTTP和HTTPS)
urls - - 使用的PHP版本
php_version - - 使用的Node.js版本
nodejs_version - - 数据库类型(mariadb、mysql、postgres)
database_type - - Web服务器(nginx-fpm、apache-fpm)
webserver_type - - 各服务的状态和详细信息
services
Resources
资源
scripts/
scripts/
- resolve-ddev-root.sh - Walks up the directory tree to find the DDEV project root from any subdirectory. Returns JSON with project root, container path, relative path, and project name.
- resolve-ddev-root.sh - 遍历目录树,从任意子目录查找DDEV项目根目录。返回包含项目根目录、容器路径、相对路径和项目名称的JSON数据。
references/
references/
- npm-projects.md - Running npm/Node.js dev servers in DDEV, including port exposure, host binding, and framework-specific examples for Vite, Next.js, and Astro.
- wordpress-multisite.md - Setup guide for WordPress Multisite with DDEV, covering subdomains, different hostnames, and subdirectory configurations with WP-CLI commands.
- npm-projects.md - 在DDEV中运行npm/Node.js开发服务器的指南,包括端口暴露、主机绑定以及Vite、Next.js和Astro等框架的具体示例。
- wordpress-multisite.md - 使用DDEV搭建WordPress多站点的指南,涵盖子域名、不同主机名以及通过WP-CLI命令配置子目录的内容。