A
A
Alexey Babiev2021-04-30 12:53:17
Nginx
Alexey Babiev, 2021-04-30 12:53:17

How to make http request between two sites in laradock?

There are two laravel projects in docker (laradock) according to the scheme "one laradock - many projects"

|-- www/
   |-- laradock/
   |-- one/
   |-- two/

// /etc/hosts
127.0.0.1   one.test
127.0.0.1   two.test

// laradock/nginx/sites
one.conf
two.conf

Each project has its own REST-API, which are tested and work from the host using postman / insomnia
Now it became necessary to use the API of one project from another using curl
Naturally, they do not see each other
Actually, this is the question and the problem: how to configure the laradok in this way so that sites can see each other?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Koryukov, 2021-04-30
@axsmak

I won’t say specifically about the laradok, but I’ll explain how it generally works.
When containers run on the same network, they are accessible to each other by domains that are equal to the name of the container. When running via docker-compose, it's a bit different. Containers see each other by service names.
Those. if you have this docker-compose.yml

services:
   front:
      image: ....
   back:
       image: ....

then the front will be able to access the back via the back domain, something like this:
file_get_contents("http://back:8080/path/to/file.txt");

Also, if you want services to access each other via public domains, and not internal ones, you can set hostname in docker-compose.yml for containers.
but in the docker-compose.yml container, you can set its hostname,
like this:
services:
   front:
      hostname: site1.ru
      image: ....
   back:
       hostname: site2.ru
       image: ....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question