docker容器hosts文件实现域名映射

当服务部署使用docker容器,需要使用hosts域名映射
共有两种方式指定容器的网络模式,分别是:

  1. host模式,使用–net=host指定。

使用参数
–network=host

宿主机中添加本地域名映射:
10.20.29.66 www.blockchain.com

容器启动方式:
docker run -itd --network=host --name nginx  nginx:1.14

  1. 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

版权声明:本文为weixin_42933886原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。