docker中为容器设置静态ip,本地测试用 (建议使用hosts的方式另一文章中有)

可以配置静态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了。

发布了48 篇原创文章 · 获赞 36 · 访问量 34万+

猜你喜欢

转载自blog.csdn.net/qq_34924407/article/details/85654878