大网数据广告活动
服务器运维问答

Docker network without IP address on host

· 52CE 我爱测

I'm trying to create a Docker network which would use an existing bridge on the host but without configuring any IP on this bridge. When I run: docker network create -o "com.docker.network.bridge.name=br0" testnet Docker automati…

问题原文

原帖链接 · spongebob · CC BY-SA 3.0

I'm trying to create a Docker network which would use an existing bridge on the host but without configuring any IP on this bridge. When I run:

docker network create -o "com.docker.network.bridge.name=br0" testnet

Docker automatically assign an IP address on the host and always use this IP as the gateway for other containers.

What I want is a network without an IP on the host and to use another container as the gateway (this container is connected to multiple networks). I have very good reasons for this setup and not letting the host directly route between these networks. Is it possible and how can I achieve that?

Thank you in advance for your help,

spongebob

已采纳解答

原帖链接 · spongebob · CC BY-SA 3.0

After looking at the source code it does not seem possible to do that with the bridge network driver. The createNetwork function always tries to setup an IPv4 even if the bridge already exists. The setupBridgeIPv4 function sets up an IPv4 on the bridge and defines this IP as the gateway for the network.

I solved my problem by using the none network driver and using pipework to manually attach the containers to my host bridge. The disadvantage of this solution is that containers must be re-attached to the bridges each time they are restarted but that can be automated with a systemd service starting after the docker one.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。