容器绑hosts

来自linux中国网wiki
跳到导航 跳到搜索

host

前端先迁移  所以要注入后端的host

到prodweb01和prod-web02上操作
添加hosts记录

docker-compose-nuxt_nuxt-pc_1

NS1=apisns.com


docker exec -i docker-compose-nuxt_nuxt-pc_1 sh -c "echo '114.5.22.113 ${NS1}'>>/etc/hosts"
docker exec -i docker-compose-nuxt_nuxt-pc_1 sh -c "echo '114.5.22.113 ${NS2}'>>/etc/hosts"


#确认hosts 映射
docker exec -i docker-compose-nuxt_nuxt-pc_1 sh -c "cat /etc/hosts"  

docker-compose-nuxt_nuxt-mobile_1

NS1=apisns.cailuw.com
NS2=webappsns.cailuw.com
NS3=adminsns.cailuw.com
NS4=prepare.cailuw.com
NS5=appsns.cailuw.com
NS6=apistatistical.cailuw.com

docker exec -i docker-compose-nuxt_nuxt-mobile_1 sh -c "echo '114.55.202.113 ${NS1}'>>/etc/hosts"
docker exec -i docker-compose-nuxt_nuxt-mobile_1 sh -c "echo '114.55.202.113 ${NS2}'>>/etc/hosts"
docker exec -i docker-compose-nuxt_nuxt-mobile_1 sh -c "echo '114.55.202.113 ${NS3}'>>/etc/hosts"
docker exec -i docker-compose-nuxt_nuxt-mobile_1 sh -c "echo '114.55.202.113 ${NS4}'>>/etc/hosts"
docker exec -i docker-compose-nuxt_nuxt-mobile_1 sh -c "echo '114.55.202.113 ${NS5}'>>/etc/hosts"
docker exec -i docker-compose-nuxt_nuxt-mobile_1 sh -c "echo '114.55.202.113 ${NS6}'>>/etc/hosts"

#确认hosts 映射
docker exec -i docker-compose-nuxt_nuxt-mobile_1 sh -c "cat /etc/hosts"  

如何还原hosts
cd /data/docker-compose-nuxt/
docker-compose down && docker-compose up -d


dnsmasq docker

测试方面


pc:
更改本机电脑的网络设置的dns地址,更改为192.168.11.244。
例如:
C:\Users\Administrator>ipconfig /flushdns                                                                                                                                                                                                       Windows IP 配置                                                                                                                                                                                                                                 已成功刷新 DNS 解析缓存。


手机:
连接公司的wifi,并把进入wan处把dns地址设置,更改为192.168.11.244。


pc和手机都更改dns地址后,最后确认使用ping命令确认一下: