How can I access another docker container using virtual host domain? Como acessar outro container docker via virtual hosts?

I have been trying to access my other domains through docker images but I have no success because they have different networks, after some research I solved it in a easy way:

First I discover my "nginx/apache" internal IP with:

docker inspect -f \
'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${YOUR_DOCKER_WEBSERVER}

Just adding that piece "extra_hosts" inside my docker-composer.yml

php-fpm-frontend:
build: phpdocker/php-fpm
container_name: php-fpm-frontend
working_dir: /application/frontend/
extra_hosts:
- "admin.dev:172.27.0.5"
volumes:
- .:/application/
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini

and inside the backend the reversal:

php-fpm-backend:
build: phpdocker/php-fpm
container_name: php-fpm-backend
working_dir: /application/backend/
extra_hosts:
- "myapp.dev:172.27.0.5"

volumes:
- .:/application/
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.4/fpm/conf.d/99-overrides.ini

after that, just rebuild the containers and Voilà!

I have been able to access the domains with "CURL" #php

--

--