Re: [docker-compose] connect from docker to host

"J.O. Aho" <[email protected]>
Newsgroups comp.lang.php
Message-ID <[email protected]>
On 24/12/2022 12.46, Custom Log wrote:
> + cat docker-compose.yml
> services:
>      web:
>          image: php:apache
>          extra_hosts:
>              - "host1:192.168.1.15"
>              - "host2:127.0.0.1"
> 
> + docker-compose run web php -r 'file_get_contents("http://host1:8010") 
> && print("OK!!!\n");'
> Creating host_web_run ... done
> OK!!!
> 
> + docker-compose run web php -r 'file_get_contents("http://host2:8010") 
> && print("OK!!!\n");'
> Creating host_web_run ... done
> Warning: file_get_contents(http://host2:8010): Failed to open stream: 
> Connection refused in Command line code on line 1
> 
> How to see
> 
> host1 work
> host2 not work
> 
> Why?

what is your host2 meant to be? the docker image itself or the host?

from the docker point of view, 127.0.0.1 is the docker itself.
if you want to access the host itself, then you need to use 
host.docker.internal

if you really want to access the dockers onw apache, then you have to 
configure that it listens to localhost/127.0.0.1.

Configure docker or apache are generally thought as off topic as it's 
nothing to do with PHP.

-- 
  //Aho
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.