问题描述
希望在phpfpm容器/ etc / hosts文件中自动添加nginx容器ip地址。
Looking to automatically add the nginx container ip address inside my phpfpm container /etc/hosts file.
在yml文件中,我有一个名为phpfpm的服务,并且我知道您可以使用extra_hosts属性将值分配到/ etc / hosts文件中,但是我不知道如何动态调用nginx容器IP。
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
是否有任何想法?
推荐答案
撰写文件中的容器将在同一网络上运行,您只能使用它们的名称。 phpfpm
和 nginx
。另外,如果您需要为同一服务使用更多名称,则需要使用别名
Containers within a compose file will run on same network and you can just their names. phpfpm
and nginx
in your case. Also if you need more names for the same service you need to use aliases
nginx:
build: ./nginx
ports:
- "80:80"
- "443:443"
volumes:
- ../public/:/var/www/html/public/
container_name: nginx
networks:
backend:
aliases:
- test.local
phpfpm:
build: ./php-fpm
volumes:
- ../public/:/var/www/html/public/
container_name: phpfpm
networks:
- backend
这篇关于将nginx容器ip动态添加到phpfpm / etc / hosts文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!