Good day.
I want to isolate the infrastructure of my new project using Docker containers and I am new to Docker. I am stuck with a problem. First of all, I will show an example of my config, and then I will describe the problem.
Config example
nginx: restart: always image: nginx:latest expose: - 80 ports: - 8181:80 # - 80:80 volumes: - ../.:/code - ./docker/nginx/hosts:/etc/nginx/conf.d/ - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf links: - php php: restart: always build: docker/php5.6-fpm # image: php:5.6-fpm # ports: # - 9000:9000 volumes: - ../.:/code links: - redis_loc - postgres_loc - memcached_loc - rabbitmq_loc This is an example. I omitted details for * _loc services. So, I have 2 local development domains, such as site1.loc and site2.loc. I use microservice architecture, and site2.loc is microservice for site1.loc.
I have a common php container for all microservice code and I have the same generic nginx for microservices, which is configured using *.loc.conf configs. Nginx listens to port 80 inside the Docker network. Hosts are available through port 8181 on the local machine. On the local machine, I have a Nginx front that proxies 80 to the appropriate 8181 hosts. Of course, in / etc / hosts on the local machine I have entries
127.0.0.1 site1.loc 127.0.0.1 site2.loc This way I can open these loc hosts in the browser and work with them independently.
Problem
The problem is that site2.loc is a microservice, and it should be accessible from the php code in site1.loc. Now, when I try to send a request from site1.loc php code to site2.loc, I get this error
'stream_socket_client(): unable to connect to site2.loc:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known)' Php can not find a way to connect.
I have already tried to use a docker-compose chip, such as extra_hosts on the nginx and php container, but this did not help me.
# extra_hosts: # - "site1.loc:nginx" # - "site2.loc:nginx" I have already tried to configure a custom network, but this is not the direction.
I also tried jwilder/nginx-proxy , but this makes hosts available on the local machine, and not inside the php container.
I clearly understand that the source of the problem is that the php container environment does not know anything about the site2.loc host. I suppose I need something like hosts map or dns.
But I don’t know how to configure it and I can’t find an example (I used to go Google for half a day).
How can I make site2.loc sufficient for site1.loc php code?
UPD
I just realized that Consul can be used. Or are there other ways without Consul?
UPD
The method with the indication of hosts on 172.17.0.1 in extra_hosts helped. Tell me, which is still better to choose a method for production - extra_hosts, dns, Consul? Provided that on my server there will be more projects nearby in containers and without.