如何修复容器的静态IP?
它说,首先我开始一个容器并进行检查
"NetworkSettings": {
"IPAddress": "XX.XX.206.98",
"IPPrefixLen": 27,
"Gateway": "XX.XX.206.105",
"Bridge": "public",
"PortMapping": null,
"Ports": {}
},
Run Code Online (Sandbox Code Playgroud)
然后我停下来,然后重启,就像
"NetworkSettings": {
"IPAddress": "XX.XX.206.99",
"IPPrefixLen": 27,
"Gateway": "XX.XX.206.105",
"Bridge": "public",
"PortMapping": null,
"Ports": {}
},
Run Code Online (Sandbox Code Playgroud)
如你所见,它改变了.我刚刚创建了一个名为public的桥,并-b=public添加了启动docker .如何为容器设置静态IP?
从 Docker 1.10 开始
# create a new bridge network with your subnet and gateway for your ip block
$ docker network create --subnet 203.0.113.0/24 --gateway 203.0.113.254 iptastic
# run a nginx container with a specific ip in that block
$ docker run --rm -it --net iptastic --ip 203.0.113.2 nginx
# curl the ip from any other place (assuming this is a public ip block duh)
$ curl 203.0.113.2
Run Code Online (Sandbox Code Playgroud)
更新
现在获取静态IP的唯一方法是通过两个脚本:pipework或ovs-docker
使用 Open vSwitch 作为多托管 Docker 容器的“含电池”版本有一个强烈的方向。
密切关注socketplane。
此行为是设计使然。
关于在未来版本中更改它有一个非常有趣的讨论。
到目前为止,唯一的方法就是回退到 Linux 容器:
docker run \
-n=false \
-lxc-conf="lxc.network.type = veth" \
-lxc-conf="lxc.network.ipv4 = 172.16.42.20/24" \
-lxc-conf="lxc.network.ipv4.gateway = 172.16.42.1" \
-lxc-conf="lxc.network.link = docker0" \
-lxc-conf="lxc.network.name = eth0" \
-lxc-conf="lxc.network.flags = up" \
-i -t my_image:my_tag /bin/bash
Run Code Online (Sandbox Code Playgroud)
因此,-n=false禁用自动 docker 网络,所有-lxc-conf选项都是根据您的需要实际定义虚拟网络。
| 归档时间: |
|
| 查看次数: |
3911 次 |
| 最近记录: |