Looking to automatically add the nginx container ip address inside my phpfpm container /etc/hosts file.
Inside my yml file, I have a service called phpfpm, and I know you can use extra_hosts attribute to assign values into the /etc/hosts file, however I don't know how to dynamically call place the nginx container IP.
nginx:
build: ./nginx
ports:
- "80:80"
- "443:443"
volumes:
- ../public/:/var/www/html/public/
container_name: nginx
networks:
- backend
phpfpm:
build: ./php-fpm
volumes:
- ../public/:/var/www/html/public/
container_name: phpfpm
extra_hosts:
- "test.local:nginx" <insert nginx ip to test.local>
networks:
- backend
Any thoughts on how to do this?
Why do you need Nginx Ip address? You can call nginx from phpfpm container by hostname
nginx
Containers within a compose file will run on same network and you can just their names.
phpfpm
andnginx
in your case. Also if you need more names for the same service you need to use aliases