1

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!

rfay
  • 9,963
  • 1
  • 47
  • 89
bfuzze
  • 438
  • 8
  • 15
  • Having the same issue with 2 containers, where the software from A wants to connect to B via OAuth2. During the Oauth2 process it seems there are several security checks to generate the access token and redirect to the caller. One of the checks fails because the caller domain is different from the hostname. – Moongazer Sep 01 '22 at 12:32

1 Answers1

4

Different projects can talk to each other in two 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 (see FAQ - latest. You just need to add a docker-compose.comm.yaml to the client project's .ddev directory like this:

version: '3.6'
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.

rfay
  • 9,963
  • 1
  • 47
  • 89
  • You could also go direct, not through the router, by using "- ddev--web:otherproject.ddev.site" – rfay Jan 21 '21 at 20:33
  • Unfortunately the link above is outdated (404), is there any new place to find more information to solve this issue? I've added "- ddev-myproject-a-web:myproject-b.ddev.site" and "- ddev-myproject-b-web:myproject-a.ddev.site" in the docker-compose files of each project, but matching the domain against the hostname still fails (during the OAuth2 process). – Moongazer Sep 01 '22 at 13:26
  • I updated the link, but you could have just gone to ddev docs and searched for "FAQ". It sounds like you might have a more extensive question, so please create a new question that represents your situation fully. – rfay Sep 01 '22 at 18:58
  • 1
    Thanks. Actually in my previous post with the hostname I was on a wrong path of the above described problem. The real reason was Curl could not access the other container. Finally "ddev-router:myproject.ddev.site" solved the issue now, but it didn't work with your direct alternative without the router ("ddev-myproject-web:myproject.ddev.site") which I've tried first. Thanks anyway for your amazing project and outstanding support everywhere :) – Moongazer Sep 01 '22 at 20:50