- 时间:2020-05-06 06:53 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:Docker容器固定IP分配详解
我们在使用docker run创建Docker容器时,可以用--net选项指定容器的网络模式,Docker有以下4种网络模式:
[list]
[*]host模式,使用--net=host指定。[/*]
[*]container模式,使用--net=container:NAME_or_ID指定。[/*]
[*]none模式,使用--net=none指定。[/*]
[*]bridge模式,使用--net=bridge指定,默认设置。[/*]
[/list]
默认选择bridge的情况下,容器启动后会通过DHCP获取一个地址,这可能不是我们想要的,本文介绍在centos7 docker环境下使用pipework脚本对容器分配固定IP。
<div class="sucaicode">
<pre class="brush:bash;">
# brctl show
# docker run -idt --net=none --name test1 registry.fjhb.cn/centos6 /bin/bash
# brctl show
# docker-enter test1
# ip a</pre>
</div>
[img]http://img.1sucai.cn/uploads/article/2018010710/20180107100151_0_54393.jpg?2017024101142[/img]
<div class="sucaicode">
<pre class="brush:bash;">
# wget https://github.com/jpetazzo/pipework/archive/master.zip
# unzip pipework-master.zip
# cp pipework-master/pipework /usr/local/bin/
# chmod +x /usr/local/bin/pipework
# pipework kbr0 test1 172.17.1.3/24@172.17.1.1
# brctl show
# docker-enter test1
# ip a
# route -n</pre>
</div>
[img]http://img.1sucai.cn/uploads/article/2018010710/20180107100151_1_65868.jpg?2017024101414[/img]
Pipework有个缺陷,容器重启后IP设置会自动消失,需要重新设置。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。