Search code examples
ddev

Communicating between ddev projects via http/s


I've been using DDev for the last six months or so. It has greatly improved my efficiency. Thanks!

I'm looking for a better way to integrate multiple sites running on separate containers. The recommended solution is to use the internal container references (e.g. ddev-projectname-web). This does not work one of my projects because the destination site relies on a matching hostname for authentication.

Scenario: SiteA communicates with SiteB via REST.

SiteA

Project-name: sitea Hostname: sitea.ddev.site Container reference: ddev-sitea-web

SiteB

Project-name: siteb Hostname: siteb.ddev.site Container reference: ddev-siteb-web

In order to authenticate with SiteB (tcp or rest), the hostname must be consistent, in this case siteb.ddev.site, so ddev-siteb-web does not work.

My current workaround is to use the SiteB hostname in REST calls from SiteA AND add internal IP to /etc/hosts on SiteA web (something like 172.1.0.1 siteb.ddev.site). I'm looking for a better solution because the hosts configuration is lost when I stop/restart SiteA and/or the IP changes when I stop/restart SiteB.

One theoretical option is a configuration setting that specifies another running docker instance and automatically adds that IP address and hostname to the integrated site's /etc/hosts file.

Thanks!


Solution

  • Different projects can talk to each other in two ways. The FAQ covers both ways.

    The first way is by using the container name directly, and I think that's what you were doing here.

    But there's an alternate way. You need to add a docker-compose.communicate.yaml to the client project's .ddev directory like this:

    services:
      web:
        external_links:
        - "ddev-router:otherproject.ddev.site"
    

    That way you can use the canonical name of the other site for communications. This only works for HTTP/S traffic, because it's going through the ddev-router, which is a reverse proxy.