I want to isolate my new project infrastructure using Docker containers and I'm newbie in Docker. I'm stuck with a problem. First of all I will show example of my config and then I will address 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 have dropped details for *_loc
services.
So, I have two local domains for development, like site1.loc
and site2.loc
. I'm use micro-service architecture and site2.loc
is a micro-service for site1.loc
.
I have common php container for all micro-services code and
I have common nginx container for all micro-services which configured with *.loc.conf
config files. Nginx listen to 80
port inside Docker network.
This hosts are available through 8181
port on host machine.
On local (host) machine I have front nginx with the same *.loc
configs configured as proxy to 8181
analogues.
Also I have in my /etc/hosts
records
127.0.0.1 site1.loc
127.0.0.1 site2.loc
So, I can open in browser both local sites and work with them separately.
The problem
The problem is, that site2.loc is a micro-service, so it should be accessible from site1.loc php code. And now, when I'm trying to send request to site2.loc from site1.loc php code I'm getting the error:
'stream_socket_client(): unable to connect to site2.loc:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known)'
Php can't find the way to site2.loc.
I have tried docker-compose feature extra_hosts
on nginx and php containers, but it's doesn't helped me.
# extra_hosts:
# - "site1.loc:nginx"
# - "site2.loc:nginx"
I have tried to configure custom network, but then I'm realized, that this is wrong way.
Also I have tried jwilder/nginx-proxy
, but it's make vhosts available just for local machine, not inside php container.
I clearly understand that source of problem is that environment inside php container doesn't know anything about site2.loc host. And I guess I need some kind of hosts mapping or dns
to be configured.
But I don't know how to implement such configuration and can't find any example (I had googled through half day yesterday).
How could I make site2.loc accessible to site1.loc php code?
UPD
I just have figured out that I need use Consul. Are there another ways without Consul?
UPD
Helped way of indicating the hosts with reference to 172.17.0.1 in extra_hosts. Prompt, how it is better to select a method for Productions - extra_hosts, dns, Consul? Given that I have on the server several projects nearby, in containers or without.