如何在Centos 7上更改Docker IP地址? [英] How to change Docker IP address on Centos 7?

查看:949
本文介绍了如何在Centos 7上更改Docker IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I installed Docker on Centos 7. Below is the output of ifconfig command

# 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

我试图更改IP docker0的地址172.17.0.1到192.168.149.5,即ens33的IP地址。我搜索了很多参考网站,但没有成功。如何在CentOS 7上设置docker0的IP地址?

I tried to change IP address of docker0 172.17.0.1 to 192.168.149.5, the IP address of ens33. I searched many ref site, but I can't make it. How can I set the ip address of docker0 on CentOS 7?

推荐答案

首先,docker配置文件的位置取决于docker版。如果您使用了一些较新的泊坞窗,则其配置将位于/etc/docker/daemon.json中。
将以下代码放入配置文件中,然后重新启动docker daemon,将更新docker bridge的IP。

First, the position of docker configuration file depends on the docker version. If some newer docker you used, its configuration will be in /etc/docker/daemon.json. Put the following code into the configuration file and restart the docker daemon, the IP of docker bridge will be updated.

{
  "bip": "192.168.1.1/24"
}

希望有帮助。

控制并使用systemd配置Docker

守护程序配置文件

这篇关于如何在Centos 7上更改Docker IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆