D
D
Dmitry Tarasov2021-09-28 15:03:15
PHP
Dmitry Tarasov, 2021-09-28 15:03:15

How to send request via curl php to localhost?

Hello.
I have a problem with sending request to centrifuge api with php. https://centrifugal.github.io/centrifugo/
I have docker compose, centrifuge works correctly.
But when I send a curl request from php to localhost, I get an error
Could not connect to port 80 localhost after 10ms: connection refused

That is, I make a request to my localhost, but php knows nothing about it at all.
How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-09-28
@fast-je

localhost in the container, hence the error.
The option is so-so, but the working one is to configure the service that runs on the host machine so that it listens on all IPs (perhaps this has already been done) and access it from the container using the gateway IP (it is available both from the host machine and from the container). The gateway IP is the one assigned to the docker bridge, you can find out with the command:

docker inspect --format='{{range .NetworkSettings.Networks}}{{.Gateway}}{{end}}' <container_name>

For convenience, you can give it a name using extra_hosts: in docker-compose.yml
A good option is to wrap the service that is currently running on the host machine in a container and add it to the same compose, then you can refer to it by the name of the service, because they will work within the same virtual network.
And a bad option is to remove the isolation for the network, that is, Use host networking . network_mode directive in docker-compose.yml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question