如何在Centos 7上更改Docker IP地址?

时间:2017-04-27 22:55:25

标签: docker centos7 docker-container

我在Centos 7上安装了Docker。下面是ifconfig命令的输出

# ifconfig

docker0: flags=4099 mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0
ether 02:42:ea:cd:a1:19 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ens33: flags=4163 mtu 1500
inet 192.168.149.5 netmask 255.255.255.0 broadcast 192.168.149.255
inet6 fe80::c494:6514:b641:e046 prefixlen 64 scopeid 0x20
ether 00:0c:29:57:00:09 txqueuelen 1000 (Ethernet)
RX packets 42800 bytes 26241065 (25.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 31687 bytes 4228571 (4.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1 (Local Loopback)
RX packets 302 bytes 29477 (28.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 302 bytes 29477 (28.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099 mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:ce:2f:27 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

我尝试将docker0 172.17.0.1的IP地址更改为192338.149.5,即ens33的IP地址。我搜索了许多参考站点,但我无法成功。如何在CentOS 7上设置docker0的ip地址?

2 个答案:

答案 0 :(得分:1)

首先,docker配置文件的位置取决于docker版本。如果你使用了一些较新的docker,它的配置将在/etc/docker/daemon.json中。 将以下代码放入配置文件并重启docker守护程序,将更新docker bridge的IP。

{
  "bip": "192.168.1.1/24"
}
希望有所帮助。

Control and configure Docker with systemd

Daemon configuration file

答案 1 :(得分:0)

这是我更改docker容器的ip地址的过程。

$("button").on("click", function(e) {
  e.preventDefault();
  $(this).parent().siblings().find(".box").removeClass("active‌​");
  $(this).toggleClass("active");
});

问题是没有这样的文件(/ etc / default / docker)。我生成了docker文件,但它不起作用。

相关问题