I’m trying to make a GET/POST request by hostname like http:://super.localhost
instead of container name.
My super.localhost
(nginx container) website available from internet browser, but from php container I can’t make curl GET request (connection refused). Only by container name works.
PHP script has 100+ hosts by CURL all of them on nginx container.
> CURL -i nginx
is works. > CURL -i super.localhost
doesn’t work. Any ideas hot to reach the response?
Everything on the one network. Ports for nginx 80:80
version: '3'
services:
nginx:
container_name: webshop-nginx
build:
context: .
dockerfile: ./nginx/nginx.docker
ports:
- "80:80"
- "8080:80"
volumes:
- ./app:/var/www/app
- ./nginx/site.conf:/etc/nginx/conf.d/default.conf
working_dir: /var/www/app
depends_on:
- php-fpm
networks:
- local
2
Answers
Actually for available hosts from inside of container need to use the aliases
Aliases need to add in web server service of
docker-compose.yml
You can add the
hostname
configuration option in your compose file, like this example:So, when in the
nginx-1
container you makecurl -i http://super.localhost/index.html
you can reach thenginx-2
container.