本文介绍了两个ddev项目之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个需要相互交互的ddev项目。遇到某些问题时,我检查了已解析的IP连接。
我通过ssh做到了project1和ping project2( ping project2.ddev.local )。
域解析为127.0.0.1
因此,我发送到该域的每个请求都将保留在当前容器中,并且不会路由到另一个项目。

I got two ddev projects that needs to interact with each other. When a ran into some issues, I check the resolved IP for the connection.I did it by ssh into project1 and ping project2 (ping project2.ddev.local)The domain resolves to 127.0.0.1So every request I send to this domain will stay in the current container and is not routet to the other project.

重现步骤:
启动两个单独的ddev容器和ssh放入其中之一。尝试使用ddev域对另一个项目执行ping操作。

Steps to reproduce:Start two separate ddev containers and ssh into one of them. Try to ping the the other project by using the ddev domain.

是否存在两个(或更多)项目可以相互交互的解决方案?

Is there a solution that two (or more) projects can interact with each other?

推荐答案

编辑2019-01-08:实际上,仅使用容器的Docker名称即可轻松完成此操作,不需要额外的docker-compose配置。对于 ddev-< projectname> -db 的数据库容器。因此,您可以使用主机名 ddev-d8composer-db 来访问名为 d8composer的项目的db容器;例如 mysql -udb -pdb -h ddev-d8composer-db db

Edit 2019-01-08: It's actually easy to do this with just the docker name of the container, no extra docker-compose config is required. For a db container that's ddev-<projectname>-db. So you can access the db container of a project named "d8composer" by using the hostname ddev-d8composer-db; for example mysql -udb -pdb -h ddev-d8composer-db db

这是另一种技术,实际上 确实有两个相互通信的项目。

Here's another technique that actually does have two projects communicating with each other.

假设您有两个名为project1和project2的项目,并且希望project2可以从project1访问db容器。

Let's say that you have two projects named project1 and project2, and you want project2 to have access to the db container from project1.

将.ddev / docker-compose.extradb.yaml添加到project2的.ddev文件夹中,内容如下:

Add a .ddev/docker-compose.extradb.yaml to project2's .ddev folder with this content:

version: '3.6'
services:
  web:
    external_links:
      - ddev-project1-db:proj1-db

现在可以从project2上的Web容器访问project1的数据库容器。例如,您可以从project2 Web容器中 mysql -h proj1-db

And now project1's database container is accessible from the web container on project2. For example, you can mysql -h proj1-db from within the project2 web container.

请注意,这是通常这是一个坏主意,最好不要让两个 dev 项目相互依赖,最好找出尽可能简单的开发环境。如果您只需要一个额外的数据库,则可能需要尝试。如果您只需要一个额外的Web容器作为API服务器或其他工具,则会更好。

Note that this is often a bad idea, it's best not to have two dev projects depend on each other, it's better to figure out development environments that are as simple as possible. If you just need an extra database, you might want to try How can I create and load a second database in ddev? . If you just need an additional web container as an API server or whatever, the other answer is better.

这篇关于两个ddev项目之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 12:01