Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

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!

question from:https://stackoverflow.com/questions/65834164/communicating-between-ddev-projects-via-http-s

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...