当服务部署使用docker容器,需要使用hosts域名映射
共有两种方式指定容器的网络模式,分别是:
- host模式,使用–net=host指定。
使用参数
–network=host
宿主机中添加本地域名映射:
10.20.29.66 www.blockchain.com
容器启动方式:
docker run -itd --network=host --name nginx nginx:1.14
- bridge模式,使用–net=bridge指定。(即 -p 宿主机映射端口:容器暴露端口)
使用参数
–add-host 域名:IP
docker run -itd \
--name nginx \
-p 8080:80 \
--add-host www.blockchain.com:10.20.29.66 \
nginx:1.14