ddev / ddev

Docker-based local PHP+Node.js web development environments
https://ddev.com
Apache License 2.0
2.76k stars 603 forks source link

Project Hostname in additional services receives the wrong IP address #5607

Closed sebastian-ehrling closed 10 months ago

sebastian-ehrling commented 11 months ago

Is there an existing issue for this?

Output of ddev debug test

I've added an additional service to my ddev project via an additional yaml file.

Everythink works fine. But i'm unable to resolve the correct ip address for the project hostname via ssh from the new container. I always get 127.0.0.1. But i want to get the ip address from the web container.

Expected Behavior

I get the ip address from the web container and not 127.0.0.1

Actual Behavior

i get the ip address 127.0.0.1

Steps To Reproduce

Steps to reproduce: ddev start ddev ssh -s myservice ping myproject.ddev.site --> Result 127.0.0.1 πŸ‘Ž

Alternative SSH via web container: ddev ssh ping myproject.ddev.site --> Result 172.19.0.7. πŸ‘

Anything else?

EXAMPLE Service YAML FILE ` version: '3.6' services: myservice: container_name: ddev-${DDEV_SITENAME}-myservice hostname: ${DDEV_SITENAME}-myservice image: image/image:latest expose:

volumes: myservice:

`

rfay commented 11 months ago

Hi @sebastian-ehrling - *.ddev.site is in DNS worldwide as 127.0.0.1. If you're inside your extra container, you can easily ping web to get direct access to the web container. If you prefer to use an alias or introduce additional lookup, you can use techniques like in https://github.com/rfay/ddev/tree/20231205_xdebug

For example, in your myservice service, try

services:
  myservice:
    external_links:
      - "ddev-router:myproject.ddev.site"

Alternately, if you want to refer directly to the web container (as opposed to the router), try

services:
  myservice:
    external_links:
      - "web:myproject.ddev.site"
sebastian-ehrling commented 11 months ago

Hi @rfay thx! The following configurations works perfect for me: external_links:

I've another question. How is it possible to use the ssh agent oder my ssh keys inside the new container myservice?

tyler36 commented 11 months ago

@sebastian-ehrling

Are you talking about ddev auth ssh ?

BTW, issue queues are not are good place to ask unrelated questions. Here's a link to the dicord server which is a great place to ask the community. πŸ˜„

jonaseberle commented 11 months ago

I would recommend to just use web unless your app really relies on the hostname or https:// certificates for example in HTTP requests (for example when doing frontend acceptance tests). For anything else any service of the same docker-compose project can access any other service by its docker-compose name (web).

sebastian-ehrling commented 11 months ago

@jonaseberle thx! Yes, i need the real hostname and certificate for an http request.

rfay commented 10 months ago

I guess this is solved. If you have new questions, please open new issues, thanks!