首页 > 其他 > 详细

docker网络配置

时间:2017-01-12 16:37:26      阅读:26      评论:0      收藏:0      [点我收藏+]

标签:docker

当docker引擎启动之后会默认创建一个网桥(docker0)用来给容器分配网络地址    

# ifconfig 
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
        inet6 fe80::42:25ff:fe3b:de51  prefixlen 64  scopeid 0x20<link>
        ether 02:42:25:3b:de:51  txqueuelen 0  (Ethernet)
        RX packets 39997  bytes 2200888 (2.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 73015  bytes 101800508 (97.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

查看网络列表

# docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
4dd7d139f7fe        bridge              bridge              local               
23ac31428cb8        host                host                local              
bd7704585780        none                null                local

查看单个网络信息

[[email protected] ~]# docker network inspect bridge                    
[
    {
        "Name": "bridge",
        "Id": "4dd7d139f7fe218fbe3ccdf67e59a16e9be827ab1525b6ec7a0090406860d529",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

创建容器时如果未指定--network 参数 默认是bridge

# docker run --name 01 --hostname 01 ab44245321a8 /bin/bash
# docker run --name 02 --hostname 02 ab44245321a8 /bin/bash

# docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "4dd7d139f7fe218fbe3ccdf67e59a16e9be827ab1525b6ec7a0090406860d529",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Containers": {
           
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

创建自己的网络

# docker network create --subnet 172.11.0.0/16 Private_network
45bf464468a472dd3826673546a02c48cc2a66587b584718fea74cdf0a039dea
# docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
              
4dd7d139f7fe        bridge              bridge              local               
23ac31428cb8        host                host                local                            
bd7704585780        none                null                local   
# docker network inspect 45bf464468a4
[
    {
        "Name": "Private_network",
        "Id": "45bf464468a472dd3826673546a02c48cc2a66587b584718fea74cdf0a039dea",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.11.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]
# docker run -itd --network 45bf464468a4 --name 04 --hostname 04  ab44245321a8 /bin/bash                                             
2a078ed5fd88bc0db21b1bc97cf2d8024713c9df03dd1571ad71a19db2d1dc15
[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
2a078ed5fd88        ab44245321a8        "/bin/bash"         About a minute ago   Up About a minute                       04
[[email protected] ~]# docker attach 2a078ed5fd88
[[email protected] /]# 
[[email protected] /]# 
[[email protected] /]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 02:42:AC:0B:00:02  
          inet addr:172.11.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe0b:2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:648 (648.0 b)  TX bytes:648 (648.0 b)


docker网络配置

标签:docker

原文:http://11889458.blog.51cto.com/11879458/1891250

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号