单机让多docker拥有多ip出口

1、创建docker 桥接网络

docker network create \

--driver bridge \

--subnet=172.30.20.0/24 \

--gateway=172.30.20.1 \

nginx-bridge-eth2

2、创建docker-nginx容器

docker run -d --name nginx-eth2-1 \

--network nginx-bridge-eth2 \

nginx

3、添加路由

echo "102 eth2-routing" >> /etc/iproute2/rt_tables

root@hwy-isms-nginx-0-30:/hskj# ip route add default via 192.168.0.1 dev eth2 table eth2-routing

root@hwy-isms-nginx-0-30:/hskj# ip rule add from 172.30.20.0/24 lookup eth2-routing

root@hwy-isms-nginx-0-30:/hskj# ip route flush cache

4、验证

docker exec -it 1676bce8da35 curl cip.cc

相关推荐
JadenOliver6 小时前
Docker 守护进程核心配置入口:daemon.json
docker·daemon.json
用户93816912553607 小时前
Ubuntu系统docker错误,failed to do request: Head "https://registry-1.docker.io/v2/...
docker
m0_748245927 小时前
Docker 容器基本操作
运维·docker·容器
咋吃都不胖lyh8 小时前
Docker 是什么?全面解析容器化技术
运维·docker·容器
阿杰 AJie8 小时前
Docker 常用镜像启动参数对照表
运维·docker·容器
db_cy_20629 小时前
Docker+Kubernetes企业级容器化部署解决方案(阶段一)
docker·容器·kubernetes·云计算·负载均衡·运维开发
王同学 学出来10 小时前
vue+nodejs项目在服务器实现docker部署
服务器·前端·vue.js·docker·node.js
last demo10 小时前
docker容器
运维·docker·容器
海鸥8110 小时前
k8s 国内无法下载docker images的分析
docker
养乐多q.♡10 小时前
docker镜像的nginx配置证书SSL,单独配置单个localtion使用证书,其他nginx配置不影响
nginx·docker·ssl