I have several php servers, let's name them api1, api2. I've set up docker-compose file which successfully run them in link with nginx, so they are accessible from host machine and working fine.
Here is example of my docker-compose.yml:
version: "3.5"
services:
nginx:
user: "root:root"
image: nginx:stable
container_name: nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./cert:/etc/nginx/ssl/
- ./vhosts/:/etc/nginx/conf.d/:cached
- ./logs/nginx:/var/log/nginx:cached
- ${ACCOUNT_PATH}:/var/www/api1:cached
- ${ACCOUNT_API_PATH}:/var/www/api2:cached
api1:
image: php-fpm-image
build:
context: "."
dockerfile: "./images/api1/Dockerfile"
user: "root:root"
container_name: account
working_dir: /var/www/api1/
volumes:
- api1path/:/var/www/api1
api2:
image: php-fpm-image
build:
context: "."
dockerfile: "./images/api2/Dockerfile"
user: "root:root"
container_name: api2
working_dir: /var/www/api2/
volumes:
- api2:/var/www/api2:cached
networks:
default:
name: domain.com
driver: bridge
In connection with this docker-compose file for functional tests:
version: '3.5'
services:
apitests:
image: apitests:latest
container_name: api_tests
volumes:
- ./config/:/opt/project/config/
- ./test_reports/screenshots:/root/.selene/screenshots/
networks:
default:
driver: bridge
external:
name: domain.com
There are next domains which are accessible from host machine:
api1.domain.com 127.0.0.1
api2.domain.com 127.0.0.1
My problem is how to connect them directly inside docker, because I need to do requests from api1 to api2, apitests to api1, api2.
When I do request, their domain resolving directly to their containers, so I receive next error
can't connect to remote host (172.21.0.8): Connection refused
from any container.
As you understand, I need that their domains resolve to NGINX container, so it can work correctly and php-fpm can return result via nginx back to me.
How do can I achieve this?