docker本地开发和测试_如何使用Docker和DDEV在本地计算机上开发Drupal 9网站

docker本地开发和测试

The author selected the Diversity in Tech Fund to receive a donation as part of the Write for DOnations program.

作者选择了“技术多元化”基金来接受捐赠,这是Write for DOnations计划的一部分。

介绍 (Introduction)

DDEV is an open-source tool that uses Docker to build local development environments for many different PHP frameworks. Using the power of containerization, DDEV can greatly simplify how you work on multiple projects that use multiple tech stacks and multiple cloud servers. DDEV includes templates for WordPress, Laravel, Magento, TYPO3, Drupal, and more.

DDEV是一种开源工具,使用Docker为许多不同PHP框架构建本地开发环境。 使用容器化功能,DDEV可以大大简化您使用多个技术堆栈和多个云服务器的多个项目的工作方式。 DDEV包括WordPressLaravelMagentoTYPO3Drupal等模板。

Drupal 9 was released on June 3, 2020 for the Drupal CMS. Known for its ease of use and a massive library of modules and themes, Drupal is a popular PHP framework for building and maintaining various websites and applications of all sizes.

Drupal 9于2020年6月3日发布,用于Drupal CMS。 Drupal以其易用性和庞大的模块和主题库而闻名,它是一个流行PHP框架,用于构建和维护各种规模的各种网站和应用程序。

In this tutorial, you will begin developing a Drupal 9 website on your local machine using DDEV. This will allow you to build your website first, and then later, when you are ready, deploy your project to a production server.

在本教程中,您将开始使用DDEV在本地计算机上开发Drupal 9网站。 这将允许您先构建网站,然后在准备就绪后将项目部署到生产服务器。

先决条件 (Prerequisites)

To complete this tutorial, you will need:

要完成本教程,您将需要:

Note: It is possible to develop Drupal 9 using DDEV on a remote server, but you will need a solution to access localhost in a web browser. The DDEV command ddev share works with ngrok, which creates a secure tunnel into your server for you and other stakeholders to view your development site. For personal use, you could also install a GUI on your remote server and access your development site through a web browser inside that interface. To do this, you could follow our guide on how to install and configure VNC on Ubuntu 20.04. For an even quicker GUI solution you can follow our guide on how to set up a remote desktop with X2Go on Ubuntu 20.04.

注意:可以在远程服务器上使用DDEV开发Drupal 9,但是您需要一种解决方案才能在Web浏览器中访问localhostDDEV命令ddev sharengrok一起使用 ,后者可为您和其他利益相关者创建进入您服务器的安全隧道,以供您查看开发站点。 对于个人用途,您还可以在远程服务器上安装GUI并通过该界面内的Web浏览器访问开发站点。 为此,您可以按照有关如何在Ubuntu 20.04上安装和配置VNC的指南进行操作。 对于更快的GUI解决方案,您可以遵循我们的指南,了解如何在Ubuntu 20.04上使用X2Go设置远程桌面

第1步-安装DDEV (Step 1 — Installing DDEV)

In this step you will install DDEV on your local machine. Option 1 includes instructions for macOS while Option 2 provides instructions for Linux. This tutorial was tested on DDEV version 1.15.0.

在此步骤中,您将在本地计算机上安装DDEV。 选项1包括针对macOS的说明,而选项2提供针对Linux的说明。 本教程已在DDEV 1.15.0版上进行了测试。

选项1 —在macOS上安装DDEV (Option 1 — Installing DDEV on macOS)

DDEV advises that macOS users install their tool using the Homebrew package manager. Use the following brew command to install the newest stable release:

DDEV建议macOS用户使用Homebrew软件包管理器安装其工具。 使用以下brew命令安装最新的稳定发行版:

  • brew tap drud/ddev && brew install drud/ddev/ddev

    brew tap drud / ddev && brew安装drud / ddev / ddev

If you prefer the absolute newest version, you can use brew to install ddev-edge:

如果您喜欢绝对最新的版本,则可以使用brew安装ddev-edge

  • brew tap drud/ddev-edge && brew install drud/ddev-edge/ddev

    brew tap drud / ddev-edge && brew安装drud / ddev-edge / ddev

If you already have a version of DDEV installed, or if you ever wish to update your version, shut down DDEV and use brew to update your installation:

如果已经安装了DDEV的版本,或者如果您希望更新版本,请关闭DDEV并使用brew更新安装:

  • ddev poweroff

    ddev关机
  • brew upgrade ddev

    酿造升级ddev

Once you have installed or updated DDEV, run ddev version to verify your software:

安装或更新DDEV之后,请运行ddev version以验证软件:

  • ddev version

    ddev版本

You will see an output like this:

您将看到类似以下的输出:


   
   
Output
DDEV-Local version v1.15.0 commit v1.15.0 db drud/ddev-dbserver-mariadb-10.2:v1.15.0 dba phpmyadmin/phpmyadmin:5 ddev-ssh-agent drud/ddev-ssh-agent:v1.15.0 docker 19.03.8 docker-compose 1.25.5 os darwin router drud/ddev-router:v1.15.0 web drud/ddev-webserver:v1.15.0

DDEV includes a powerful CLI, or command line interface. Run ddev to learn about some common commands:

DDEV包含功能强大的CLI或命令行界面。 运行ddev以了解一些常用命令:

  • ddev

    ddev

You will see the following output:

您将看到以下输出:


   
   
Output
Create and maintain a local web development environment. Docs: https://ddev.readthedocs.io Support: https://ddev.readthedocs.io/en/stable/#support Usage: ddev [command] Available Commands: auth A collection of authentication commands composer Executes a composer command within the web container config Create or modify a ddev project configuration in the current directory debug A collection of debugging commands delete Remove all project information (including database) for an existing project describe Get a detailed description of a running ddev project. exec Execute a shell command in the container for a service. Uses the web service by default. export-db Dump a database to a file or to stdout help Help about any command hostname Manage your hostfile entries. import-db Import a sql file into the project. import-files Pull the uploaded files directory of an existing project to the default public upload directory of your project. list List projects logs Get the logs from your running services. pause uses 'docker stop' to pause/stop the containers belonging to a project. poweroff Completely stop all projects and containers pull Pull files and database using a configured provider plugin. restart Restart a project or several projects. restore-snapshot Restore a project's database to the provided snapshot version. sequelpro This command is not available since sequel pro.app is not installed share Share project on the internet via ngrok. snapshot Create a database snapshot for one or more projects. ssh Starts a shell session in the container for a service. Uses web service by default. start Start a ddev project. stop Stop and remove the containers of a project. Does not lose or harm anything unless you add --remove-data. version print ddev version and component versions Flags: -h, --help help for ddev -j, --json-output If true, user-oriented output will be in JSON format. -v, --version version for ddev Use "ddev [command] --help" for more information about a command.

For more information about using the DDEV CLI, visit the official DDEV documentation.

有关使用DDEV CLI的更多信息, 请访问官方DDEV文档

With DDEV installed on your local machine, you are now ready to install Drupal 9 and begin developing a website.

在本地计算机上安装了DDEV之后,现在就可以安装Drupal 9并开始开发网站了。

选项2 —在Linux上安装DDEV (Option 2 — Installing DDEV on Linux)

On a Linux operating system, you can install DDEV using Homebrew for Linux or using the official installation script. On Ubuntu, begin by updating your list of packages in the apt package manager (you can use apt in Debian, otherwise use the equivalent package manager associated with your Linux distribution):

在Linux操作系统上,可以使用Homebrew for Linux或使用官方安装脚本来安装DDEV。 在Ubuntu上,首先更新apt软件包管理器中的软件包列表(您可以在Debian中使用apt ,否则请使用与Linux发行版关联的等效软件包管理器):

  • sudo apt update

    sudo apt更新

Now install some prerequisite packages from Ubuntu’s official repository:

现在,从Ubuntu的官方存储库安装一些必备软件包:

  • sudo apt install build-essential apt-transport-https ca-certificates software-properties-common curl

    sudo apt install build-essential apt-transport-https ca-certificates software-properties-common curl

These packages will allow you to download the DDEV installation script from their official GitHub repository.

这些软件包将允许您从其官方GitHub存储库下载DDEV安装脚本。

Now download the script:

现在下载脚本:

  • curl -O https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh

    curl -O https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh

Before running the script, open it in nano or your preferred text editor and inspect its contents:

在运行脚本之前,请在nano或您喜欢的文本编辑器中将其打开并检查其内容:

nano install_ddev.sh

Once you have reviewed the script’s contents and you are satisfied, save and close the file. Now you are ready to run the installation script.

查看脚本的内容并感到满意后,保存并关闭文件。 现在您可以运行安装脚本了。

Use the chmod command to make the script executable:

使用chmod命令使脚本可执行:

  • chmod +x install_ddev.sh

    chmod + x install_ddev.sh

Now run the script:

现在运行脚本:

  • ./install_ddev.sh

    ./install_ddev.sh

The installation process might prompt you to confirm some settings or to enter your sudo password. Once the installation completes, you will have DDEV available on your Linux operating system.

安装过程可能会提示您确认某些设置或输入您的sudo密码。 安装完成后,您将在Linux操作系统上使用DDEV。

Run ddev version to verify your software:

运行ddev version以验证您的软件:

  • ddev version

    ddev版本

You will see an output like this:

您将看到类似以下的输出:


   
   
Output
DDEV-Local version v1.15.0 commit v1.15.0 db drud/ddev-dbserver-mariadb-10.2:v1.15.0 dba phpmyadmin/phpmyadmin:5 ddev-ssh-agent drud/ddev-ssh-agent:v1.15.0 docker 19.03.8 docker-compose 1.25.5 os linux router drud/ddev-router:v1.15.0 web drud/ddev-webserver:v1.15.0

DDEV is a powerful CLI, or command line interface. Run ddev without anything else to learn about some common commands:

DDEV是功能强大的CLI或命令行界面。 无需其他任何ddev即可运行ddev ,以了解一些常用命令:

  • ddev

    ddev

You will see the following output:

您将看到以下输出:


   
   
Output
Create and maintain a local web development environment. Docs: https://ddev.readthedocs.io Support: https://ddev.readthedocs.io/en/stable/#support Usage: ddev [command] Available Commands: auth A collection of authentication commands composer Executes a composer command within the web container config Create or modify a ddev project configuration in the current directory debug A collection of debugging commands delete Remove all project information (including database) for an existing project describe Get a detailed description of a running ddev project. exec Execute a shell command in the container for a service. Uses the web service by default. export-db Dump a database to a file or to stdout help Help about any command hostname Manage your hostfile entries. import-db Import a sql file into the project. import-files Pull the uploaded files directory of an existing project to the default public upload directory of your project. list List projects logs Get the logs from your running services. pause uses 'docker stop' to pause/stop the containers belonging to a project. poweroff Completely stop all projects and containers pull Pull files and database using a configured provider plugin. restart Restart a project or several projects. restore-snapshot Restore a project's database to the provided snapshot version. sequelpro This command is not available since sequel pro.app is not installed share Share project on the internet via ngrok. snapshot Create a database snapshot for one or more projects. ssh Starts a shell session in the container for a service. Uses web service by default. start Start a ddev project. stop Stop and remove the containers of a project. Does not lose or harm anything unless you add --remove-data. version print ddev version and component versions Flags: -h, --help help for ddev -j, --json-output If true, user-oriented output will be in JSON format. -v, --version version for ddev Use "ddev [command] --help" for more information about a command.

For more information about using the DDEV CLI, you can visit the official DDEV documentation.

有关使用DDEV CLI的更多信息, 请访问官方DDEV文档

With DDEV installed on your local machine, you are now ready to deploy Drupal 9 and begin developing a website.

在本地计算机上安装DDEV之后,您现在就可以部署Drupal 9并开始开发网站。

第2步-使用DDEV部署新的Drupal 9站点 (Step 2 — Deploying a New Drupal 9 Site Using DDEV)

With DDEV running, you will now use it to create a Drupal-specific filesystem, install Drupal 9, and then initiate a standard website project.

在运行DDEV的情况下,您现在将使用它来创建特定于Drupal的文件系统,安装Drupal 9,然后启动一个标准的网站项目。

First, you will create a project root directory and then move inside it. You will run all remaining commands from this location. This tutorial will use d9test, but you are free to name your directory something else. Note, however, that DDEV doesn’t handle hyphenated names well. It is considered a best practice to avoid directory names like my-project or drupal-site-1.

首先,您将创建一个项目根目录,然后在其中移动。 您将从该位置运行所有剩余命令。 本教程将使用d9test ,但是您可以随意命名目录。 但是请注意,DDEV不能很好地处理带连字符的名称。 最好避免使用目录名,例如my-projectdrupal-site-1

Create your project root directory and navigate inside:

创建项目根目录并在其中导航:

  • mkdir d9test

    mkdir d9test

  • cd d9test

    cd d9test

DDEV excels at creating directory trees that match specific CMS platforms. Use the ddev config command to create a directory structure specific to Drupal 9:

DDEV擅长创建与特定CMS平台匹配的目录树 。 使用ddev config命令创建特定于Drupal 9的目录结构:

  • ddev config --project-type=drupal9 --docroot=web --create-docroot

    ddev配置--project-type = drupal9 --docroot = web --create-docroot

You will see an output like this:

您将看到类似以下的输出:


   
   
Output
Creating a new ddev project config in the current directory (/Users/sammy/d9test) Once completed, your configuration will be written to /Users/sammy/d9test/.ddev/config.yaml Created docroot at /Users/sammy/d9test/web You have specified a project type of drupal9 but no project of that type is found in /Users/sammy/d9test/web Ensuring write permissions for d9new No settings.php file exists, creating one Existing settings.php file includes settings.ddev.php Configuration complete. You may now run 'ddev start'.

Because you passed --project-type=drupal9 to your ddev config command, DDEV created several subdirectories and files that represent the default organization for a Drupal website. Your project directory tree will now look like this:

因为您在ddev config命令中传递了--project-type= drupal9 ,所以DDEV创建了几个子目录和文件,这些子目录和文件代表了Drupal网站的默认组织。 您的项目目录树现在将如下所示:

A Drupal 9 directory tree
Drupal 9目录树
.
├── .ddev
│   ├── .gitignore
│   ├── config.yaml
│   ├── db-build
│   │   └── Dockerfile.example
│   └── web-build
│       └── Dockerfile.example
└── web
    └── sites
        └── default
            ├── .gitignore
            ├── settings.ddev.php
            └── settings.php

6 directories, 7 files

.ddev/ will be the main folder for the ddev configuration. web/ will be the docroot for your new project; it will contain several specific settings. files. You now have the initial scaffolding for your new Drupal project.

.ddev/将是ddev配置的主文件夹。 web/将是您新项目的文档根目录; 它将包含几个特定的settings. 文件。 现在,您有了新的Drupal项目的初始脚手架。

Your next step is to initialize your platform, which will build the necessary containers and networking configurations. DDEV binds to ports 80 and 443, so if you are running a web server like Apache on your machine, or anything else that uses those ports, stop those services before continuing.

下一步是初始化平台,这将构建必要的容器和网络配置。 DDEV绑定到端口80443 ,因此,如果您在计算机上运行Apache之类的Web服务器,或使用这些端口的任何其他服务器,请先停止这些服务,然后再继续。

Use the ddev start command to initialize your platform:

使用ddev start命令初始化平台:

  • ddev start

    ddev开始

This will build all the Docker-based containers for your project, which include a web container, a database container, and phpmyadmin. When the initialization completes you will see an output like this (your port number might differ):

这将为您的项目构建所有基于Docker的容器,其中包括Web容器,数据库容器和phpmyadmin 。 初始化完成后,您将看到以下输出(您的端口号可能有所不同):


   
   
Output
... Successfully started d9test Project can be reached at http://d9test.ddev.site http://127.0.0.1:32773

Note: Remember that DDEV is starting Docker containers behind the scenes here. If you want to view those containers or verify that they are running, you can always use the docker ps command:

注意:请记住,DDEV在这里是在后台启动Docker容器。 如果要查看那些容器或确认它们正在运行,则可以始终使用docker ps命令:

  • docker ps

    码头工人ps

Alongside any other containers that you are currently running, you will find four new containers, each running a different image: php-myadmin, ddev-webserver, ddev-router, and ddev-dbserver-mariadb.

除了当前正在运行的任何其他容器之外,您还将找到四个新容器,每个容器运行不同的映像: php-myadminddev-webserverddev-routerddev-dbserver-mariadb

ddev start has successfully built your containers and given you an output with two URLs. While this output says that your project “can be reached at http://d9test.ddev.site and http://127.0.0.1:32773,” visiting these URLs right now will throw an error. Starting with Drupal 8, the Drupal core and the contrib modules function like dependencies. Therefore, you’ll first need to finish installing Drupal using Composer, the package manager for PHP projects, before anything loads in your web browser.

ddev start已成功构建了容器,并为您提供了两个URL的输出。 虽然这种输出说,你的项目“可以达到http:// d9test .ddev.sitehttp://127.0.0.1: 32773 ,”访问这些网址,马上就会抛出一个错误。 从Drupal 8开始,Drupal核心和contrib模块的功能类似于依赖项。 因此,在将任何内容加载到Web浏览器之前,您首先需要使用Composer (PHP项目的软件包管理器)完成Drupal的安装。

One of the most useful and elegant features of DDEV is that you can pass Composer commands through the DDEV CLI and into your containerized environment. This means that you can separate your machine’s specific configuration from your development environment. You no longer have to manage the various file path, dependency, and version issues that generally accompany local PHP development. Moreover, you can quickly context-switch between multiple projects using different frameworks and tech stacks with minimal effort.

DDEV的最有用和最优雅的功能之一是,您可以通过DDEV CLI将Composer命令传递到您的容器化环境中。 这意味着您可以将计算机的特定配置与开发环境分开。 您不再需要管理通常伴随本地PHP开发的各种文件路径,依赖关系和版本问题。 此外,您可以轻松地使用不同的框架和技术堆栈在多个项目之间快速进行上下文切换。

Use the ddev composer command to download drupal/recommended-project. This will download Drupal core, its libraries, and other related resources and then create a default project:

使用ddev composer命令下载drupal/recommended-project 。 这将下载Drupal核心,其库和其他相关资源,然后创建一个默认项目:

  • ddev composer create "drupal/recommended-project"

    ddev作曲家创建“ drupal / recommended-project”

Now download one final component called Drush, or Drupal Shell. This tutorial will only use one drush command, and this tutorial provides an alternative, but drush is a powerful CLI for Drupal development that can improve your efficiency.

现在下载一个名为Drush或Drupal Shell的最终组件。 本教程仅使用一个drush命令,并且本教程提供了另一种方法,但是drush是用于Drupal开发的功能强大的CLI,可以提高效率。

Use ddev composer to install drush:

使用ddev composer安装drush

  • ddev composer require "drush/drush"

    ddev作曲家需要“ drush / drush”

You have now built a default Drupal 9 project and installed drush. Now you will view your project in a browser and configure your website’s settings.

现在,您已经构建了一个默认的Drupal 9项目并安装了drush 。 现在,您将在浏览器中查看项目并配置网站的设置。

步骤3 —配置您的Drupal 9项目 (Step 3 — Configuring Your Drupal 9 Project)

Now that you have installed Drupal 9 you can visit your new project in your browser. To do this, you can rerun ddev start and copy one of the two URLs that it outputs, or you can use the following command, which will automatically launch your site in a new browser window:

既然已经安装了Drupal 9,就可以在浏览器中访问新项目。 为此,您可以重新运行ddev start并复制其输出的两个URL之一,或者可以使用以下命令,它将在新的浏览器窗口中自动启动您的站点:

  • ddev launch

    ddev启动

You will encounter the standard Drupal installation wizard.

您将遇到标准的Drupal安装向导。

Here you have two options. You can use this UI and follow the wizard through installation, or you can return to your terminal and pass a drush command through ddev. The latter option will automate the installation process and set admin as both your username and password.

在这里,您有两个选择。 您可以使用此UI,然后按照向导完成安装,也可以返回到你的终端,并通过一个drush通过命令ddev 。 后一个选项将自动执行安装过程,并将admin设置为用户名和密码。

选项1-使用向导 (Option 1 — Using the Wizard)

Return to the wizard in your browser. Under Choose language select a language from the drop-down menu and click Save and continue. Now select an installation profile. You can choose between Standard, Minimal, and Demo. Make your choice and then click Save and continue. Drupal will automatically verify your requirements, set up a database, and install your site. Your last step is to customize a few configurations. Add a site name and a site email address that ends in your domain. Then choose a username and password. Choose a strong password and keep your credentials somewhere safe. Lastly, add a private email address that you regularly check, fill in the regional settings, and press Save and continue.

返回浏览器中的向导。 在选择语言”下,从下拉菜单中选择一种语言,然后单击“ 保存并继续” 。 现在选择一个安装配置文件。 您可以在StandardMinimalDemo之间进行选择。 做出选择,然后单击“ 保存并继续” 。 Drupal将自动验证您的要求,建立数据库并安装您的站点。 最后一步是自定义一些配置。 添加以您的域结尾的网站名称和网站电子邮件地址。 然后选择一个用户名和密码。 选择一个安全的密码,并将您的凭据保存在安全的地方。 最后,添加您要定期检查的私人电子邮件地址,填写区域设置,然后按保存并继续

Your new site will load with a welcome message.

您的新站点将加载欢迎消息。

选项2-使用命令行 (Option 2 — Using the Command Line)

From your project’s root directory, run this ddev exec command to install a default Drupal site using drush:

在项目的根目录中,运行以下ddev exec命令以使用drush安装默认的Drupal站点:

  • ddev exec drush site:install --account-name=admin --account-pass=admin

    ddev exec drush站点:安装--account-name = admin --account-pass = admin

This will create your site just like the wizard will but with some boilerplate configurations. Your username and password will be admin.

这将像向导一样创建您的站点,但是具有一些样板配置。 您的用户名和密码将为admin

Now launch the site to view it in your browser:

现在启动网站以在浏览器中查看它:

  • ddev launch

    ddev启动

You are now ready to begin building your website, but it is considered best practice to check that your permissions are correct for the /sites/web/default directory. While you are working locally, this is not a significant concern, but if you transfer these permissions to a production server, they will pose a security risk.

现在,您可以开始构建网站了,但是最好的做法是检查/sites/web/default目录的权限是否正确。 当您在本地工作时,这不是一个大问题,但是,如果将这些权限转移到生产服务器,则将带来安全风险。

步骤4 —检查您的权限 (Step 4 — Checking Your Permissions)

During the wizard installation, or when your welcome page first loads, you might see a warning about the permissions settings on your /sites/web/default directory and one file inside that directory: settings.php.

在向导的安装,或者当你的欢迎页面第一次加载时,你可能会看到关于您的权限设置警告/sites/web/default目录和一个文件是目录中: settings.php

After the installation script runs, Drupal will try to set the web/sites/default directory permissions to read and execute for all groups: this is a 555 permissions setting. It will also attempt to set permissions for default/settings.php to read-only, or 444. If you encounter this warning, run these two chmod commands from your project’s root directory. Failure to do so poses a security risk:

安装脚本运行后, Drupal将尝试设置web/sites/default目录权限以readexecute所有组 :这是555权限设置。 它还将尝试将default/settings.php权限default/settings.phpread-only444 。 如果遇到此警告,请从项目的根目录运行这两个chmod命令。 否则会带来安全风险:

  • chmod 555 web/sites/default

    chmod 555网站/站点/默认
  • chmod 444 web/sites/default/settings.php

    chmod 444网站/站点/默认/settings.php

To verify that you have the correct permissions, run this ls command with the a, l, h, and d switches:

要验证您是否具有正确的权限,请使用alhd开关运行以下ls命令:

  • ls -alhd web/sites/default web/sites/default/settings.php

    ls -alhd网站/网站/默认网站/网站/默认/settings.php

Check that your permissions match the following output:

检查您的权限是否与以下输出匹配:


   
   
Output
dr-xr-xr-x 8 sammy staff 256 Jul 21 12:56 web/sites/default -r--r--r-- 1 sammy staff 249 Jul 21 12:12 web/sites/default/settings.php

You are now ready to develop a Drupal 9 website on your local machine.

现在您可以在本地计算机上开发Drupal 9网站了。

步骤5 —在Drupal中创建您的第一篇文章 (Step 5 — Creating Your First Post in Drupal)

To test some of Drupal’s functionality, you will now create a post using the web UI.

为了测试Drupal的某些功能,您现在将使用Web UI创建一个帖子。

From your site’s initial page, click the Content button on the upper menu’s left-hand edge. Now click the blue add content button. A new page will appear. Click Article, and another page will appear.

在您网站的初始页面上,单击上方菜单左边缘的“ 内容”按钮。 现在,单击蓝色的添加内容按钮。 将会出现一个新页面。 点击文章 ,将出现另一个页面。

Add whatever title and content you like. You can add an image, too, like one of DigitalOcean’s wallpapers. When ready, click the blue save button.

添加您喜欢的任何标题和内容。 您也可以添加图像,例如DigitalOcean的墙纸之一 。 准备就绪后,单击蓝色的保存按钮。

Your first post will appear on your website.

您的第一篇文章将出现在您的网站上。

You are now developing a Drupal 9 website on your local machine without ever interacting with a server, thanks to Docker and DDEV. In the following step, you will manage the DDEV container to accomodate your workflow.

现在,借助Docker和DDEV,您无需与服务器进行交互即可在本地计算机上开发Drupal 9网站。 在接下来的步骤中,您将管理DDEV容器以适应您的工作流程。

第6步-管理DDEV容器 (Step 6 — Managing the DDEV Container)

When you have finished developing your project, or when you want to take a break, you can stop your DDEV container without worrying about data loss. DDEV can manage rapid context-switching among many projects; this is one of its most useful features. Your code and data are always preserved in your project directory, even after you stop or delete the DDEV container.

完成项目开发后,或想休息一下时,可以停止DDEV容器而不必担心数据丢失。 DDEV可以管理许多项目之间的快速上下文切换; 这是它最有用的功能之一。 即使停止或删除DDEV容器,代码和数据也始终保留在项目目录中。

To free up resources, you can stop DDEV at any time. From your project’s root directory, run the following command:

要释放资源,您可以随时停止DDEV。 在项目的根目录中,运行以下命令:

  • ddev stop

    ddev停止

DDEV is available globally, so you can run ddev commands from anywhere, as long as you specify the DDEV project:

DDEV在全球范围内可用,因此只要指定DDEV项目,就可以从任何地方运行ddev命令:

  • ddev stop d9test

    ddev停止d9test

You can also view all your projects at once using ddev list:

您还可以使用ddev list一次查看所有项目:

  • ddev list

    ddev列表

DDEV includes many other useful commands.

DDEV包括许多其他有用的命令

You can restart DDEV and continue developing locally at any time.

您可以随时重新启动DDEV并继续在本地进行开发。

结论 (Conclusion)

In this tutorial, you used Docker and the power of containerization to develop a Drupal site locally, with the help of DDEV. DDEV also integrates well with numerous IDEs, and it provides built-in PHP debugging for Atom, PHPStorm, and Visual Studio Code (vscode). From here, you can also learn more about creating development environments for Drupal with DDEV or developing other PHP frameworks like Wordpress.

在本教程中,您使用Docker和容器化的功能在DDEV的帮助下在本地开发了Drupal站点。 DDEV还与许多IDE很好地集成在一起,并且为AtomPHPStormVisual Studio Code(vscode)提供了内置PHP调试。 从这里,您还可以了解有关使用DDEV为Drupal创建开发环境开发其他PHP框架(如Wordpress)的更多信息

翻译自: https://www.digitalocean.com/community/tutorials/how-to-develop-a-drupal-9-website-on-your-local-machine-using-docker-and-ddev

docker本地开发和测试

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值