码迷,mamicode.com
首页 > 其他好文 > 详细

docker固定IP重启不变的方法

时间:2017-02-19 14:32:22      阅读:632      评论:0      收藏:0      [点我收藏+]

标签:ref   format   cas   create   启动   err   lin   stat   127.0.0.1   

来源于https://github.com/lioncui/docker-static-ip

Env

hello all. This script can configure container‘s ip-address persistence. To confirm before use:

  1. pip install docker-py
  2. yum install bridge-utils -y

Demo

cd docker-static-ip
python duration.py(这个进程一定要启动)

run a test container

[root@image docker-static-ip]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos6             base                4fbd1376f4f6        4 weeks ago         311.3 MB

[root@image docker-static-ip]# docker run -d --net=none 4fbd1376f4f6 tail -f /var/log/yum.log
[root@image docker-static-ip]# docker ps
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
71792e4003d8        centos6:base        "tail -f /var/log/yu   34 minutes ago      Up 26 minutes                           serene_albattani
[root@image docker-static-ip]# docker exec -i 71792e4003d8 ip a
15: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever

configure duration

[root@image docker-static-ip]# echo >> "71792e4003d8,docker0,172.17.42.30/16,172.17.42.1" >> containers.cfg

formation: [container-id],[bridge-name],[ipaddress/netmask],[gateway]

check

[root@image docker-static-ip]# docker exec -i 71792e4003d8 ip a
15: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
16: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 0a:d9:1d:00:be:71 brd ff:ff:ff:ff:ff:ff
    inet 172.17.42.30/16 scope global eth0
    inet6 fe80::8d9:1dff:fe00:be71/64 scope link 
       valid_lft forever preferred_lft forever

restart container test

[root@image docker-static-ip]# docker stop 71792e4003d8
71792e4003d8
[root@image docker-static-ip]# docker start 71792e4003d8
71792e4003d8
[root@image docker-static-ip]# docker exec -i 71792e4003d8 ip a
18: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
19: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 8a:85:16:6d:fc:08 brd ff:ff:ff:ff:ff:ff
    inet 172.17.42.30/16 scope global eth0
    inet6 fe80::8885:16ff:fe6d:fc08/64 scope link 
       valid_lft forever preferred_lft forever

OK,static ip is not change !

docker固定IP重启不变的方法

标签:ref   format   cas   create   启动   err   lin   stat   127.0.0.1   

原文地址:http://www.cnblogs.com/puremans/p/6415620.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!