可以配置静态IP。
在docker-compose.yml中。
首先,配置虚拟网卡driver和subnet:
networks:
net-default:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.0.0.0/24
然后设置nginx的静态IP:
nginx:
#其他配置…
networks:
net-default:
ipv4_address: 10.0.0.10
再在php中设置extra_hosts:
php54:
#其他配置…
extra_hosts:
- “project.com:10.0.0.10”
networks:
- net-default
最后重新build一下,就OK了。