日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

目錄
  • 了解 docker network
    • docker network –help
    • docker network create –help
  • 創建網絡
    • 創建 mynet 網絡
    • 查看網卡
    • 查看網絡
    • 查看 mynet 網絡詳細信息
  • 啟動容器,并加入mynet網絡
    • 啟動 mynet-centos01 , mynet-tomcat01 并加入mynet網絡
    • 查看mynet網橋信息
    • 進入 mynet-centos01 測試連接 mynet-tomcat01
    • 結論
  • 思考問題:

    了解 docker network

    通過下面的命令來獲取幫助

    docker network –help

    Commands:
      connect     Connect a container to a network
      create      Create a network
      disconnect  Disconnect a container from a network
      inspect     Display detailed information on one or more networks
      ls          List networks
      prune       Remove all unused networks
      rm          Remove one or more networks
    

    docker network create –help

    Options:
          --attachable           Enable manual container attachment
          --aux-address map      Auxiliary IPv4 or IPv6 addresses used by Network driver (default map[])
          --config-from string   The network from which to copy the configuration
          --config-only          Create a configuration only network
      -d, --driver string        Driver to manage the Network (default "bridge")
          --gateway strings      IPv4 or IPv6 Gateway for the master subnet   # 網關
          --ingress              Create swarm routing-mesh network
          --internal             Restrict external access to the network
          --ip-range strings     Allocate container ip from a sub-range
          --ipam-driver string   IP Address Management Driver (default "default")
          --ipam-opt map         Set IPAM driver specific options (default map[])
          --ipv6                 Enable IPv6 networking
          --label list           Set metadata on a network
      -o, --opt map              Set driver specific options (default map[])
          --scope string         Control the network's scope
          --subnet strings       Subnet in CIDR format that represents a network segment  #子網
    

    創建網絡

    • –driver bridge 網絡類型,默認bridge網橋
    • –subnet 192.168.0.0/16 子網
    • –gateway 192.168.0.1 網關

    創建 mynet 網絡

    docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet
    0096a971fd2c66400e53cbae5e53eceedc2f90d5685917e9534640a3535c0ef1
    

    查看網卡

    [root@--- ~]# ip addr
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:16:3e:0a:00:34 brd ff:ff:ff:ff:ff:ff
        inet 172.31.81.32/20 brd 172.31.95.255 scope global dynamic eth0
           valid_lft 291870572sec preferred_lft 291870572sec
    3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
        link/ether 02:42:a4:2f:c5:62 brd ff:ff:ff:ff:ff:ff
        inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
           valid_lft forever preferred_lft forever
    140: br-799426d70aa2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
        link/ether 02:42:7f:01:1d:00 brd ff:ff:ff:ff:ff:ff
        inet 172.18.0.1/16 brd 172.18.255.255 scope global br-799426d70aa2     # test-network
           valid_lft forever preferred_lft forever
    176: br-0096a971fd2c: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
        link/ether 02:42:d9:14:c1:d3 brd ff:ff:ff:ff:ff:ff
        inet 192.168.0.1/16 brd 192.168.255.255 scope global br-0096a971fd2c   # mynet 
           valid_lft forever preferred_lft forever
    

    查看網絡

    [root@--- ~]# docker network ls
    NETWORK ID     NAME           DRIVER    SCOPE
    feafa30d4051   bridge         bridge    local
    e8bf4fced9e2   host           host      local
    0096a971fd2c   mynet          bridge    local  # 自定義bridge網橋
    6263db0933b9   none           null      local
    799426d70aa2   test-network   bridge    local
    

    查看 mynet 網絡詳細信息

    [root@--- ~]# docker network inspect 0096a971fd2c
    [
        {
            "Name": "mynet",
            "Id": "0096a971fd2c66400e53cbae5e53eceedc2f90d5685917e9534640a3535c0ef1",
            "Created": "2021-10-04T10:18:09.113847736+08:00",
            "Scope": "local",
            "Driver": "bridge",  # mynet 網絡類型
            "EnableIPv6": false,
            "IPAM": {
                "Driver": "default",
                "Options": {},
                "Config": [
                    {
                        "Subnet": "192.168.0.0/16",   # mynet 子網
                        "Gateway": "192.168.0.1"      # mynet 網關
                    }
                ]
            },
            "Internal": false,
            "Attachable": false,
            "Ingress": false,
            "ConfigFrom": {
                "Network": ""
            },
            "ConfigOnly": false,
            "Containers": {},
            "Options": {},
            "Labels": {}
        }
    ]
    

    啟動容器,并加入mynet網絡

    啟動 mynet-centos01 , mynet-tomcat01 并加入mynet網絡

    [root@--- ~]# docker run -it -P --name mynet-tomcat01 --net mynet tomcat
    [root@--- ~]# docker run -it -P --name mynet-centos01 --net mynet centos
    

    查看mynet網橋信息

    [root@--- ~]# docker network inspect 0096
    [
        {
            "Name": "mynet",
            "Id": "0096a971fd2c66400e53cbae5e53eceedc2f90d5685917e9534640a3535c0ef1",
            "Created": "2021-10-04T10:18:09.113847736+08:00",
            "Scope": "local",
            "Driver": "bridge",
            "EnableIPv6": false,
            "IPAM": {
                "Driver": "default",
                "Options": {},
                "Config": [
                    {
                        "Subnet": "192.168.0.0/16",
                        "Gateway": "192.168.0.1"
                    }
                ]
            },
            "Internal": false,
            "Attachable": false,
            "Ingress": false,
            "ConfigFrom": {
                "Network": ""
            },
            "ConfigOnly": false,
            "Containers": {
                "2fac920eebd505794c4a27ef4efdf531d32805e8663bded93a473bd28236bc27": {
                    "Name": "mynet-centos01",
                    "EndpointID": "3aff0752e641651a446ec490faa000812417855739086b2edb584ac2a95a26dd",
                    "MacAddress": "02:42:c0:a8:00:02",
                    "IPv4Address": "192.168.0.2/16",
                    "IPv6Address": ""
                },
                "3dceda051252b6970fe2156bac7710ba6489a97aac68c49b1c85a2f130d0556f": {
                    "Name": "mynet-tomcat01",
                    "EndpointID": "9f52b19493d35c48fe9b33a319de5dbe54c50de1a5d049103cb4e39bfe645f1b",
                    "MacAddress": "02:42:c0:a8:00:03",
                    "IPv4Address": "192.168.0.3/16",
                    "IPv6Address": ""
                }
            },
            "Options": {},
            "Labels": {}
        }
    ]
    
    

    進入 mynet-centos01 測試連接 mynet-tomcat01

    # 發現通過容器ip和容器名都可以連接
    
    [root@--- ~]# docker exec -it 2fac920eebd5 /bin/sh
    sh-4.4# ping
    sh-4.4# ping 192.168.0.3   # 通過容器ip連接
    PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data.
    64 bytes from 192.168.0.3: icmp_seq=1 ttl=64 time=0.140 ms
    64 bytes from 192.168.0.3: icmp_seq=2 ttl=64 time=0.110 ms
    ^C
    --- 192.168.0.3 ping statistics ---
    4 packets transmitted, 4 received, 0% packet loss, time 3000ms
    rtt min/avg/max/mdev = 0.110/0.121/0.140/0.016 ms
    
    sh-4.4# ping mynet-tomcat01   # 通過容器名連接
    PING mynet-tomcat01 (192.168.0.3) 56(84) bytes of data.
    64 bytes from mynet-tomcat01.mynet (192.168.0.3): icmp_seq=1 ttl=64 time=0.078 ms
    64 bytes from mynet-tomcat01.mynet (192.168.0.3): icmp_seq=2 ttl=64 time=0.131 ms
    ^C
    --- mynet-tomcat01 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2001ms
    rtt min/avg/max/mdev = 0.078/0.110/0.131/0.026 ms
    sh-4.4# 
    

    結論

    在同一網絡下的容器,發現通過容器ip容器名都可以連接

    思考問題:

    其它網絡下的容器可以直接訪問mynet網絡下的容器嗎?

    答案:不可以

    解決方法: 讓別的網絡下的容器加入到mynet網絡下

    Docker自定義網絡詳解

    分享到:
    標簽:Docker 服務器 網絡 自定義 詳解
    用戶無頭像

    網友整理

    注冊時間:

    網站:5 個   小程序:0 個  文章:12 篇

    • 51998

      網站

    • 12

      小程序

    • 1030137

      文章

    • 747

      會員

    趕快注冊賬號,推廣您的網站吧!
    最新入駐小程序

    數獨大挑戰2018-06-03

    數獨一種數學游戲,玩家需要根據9

    答題星2018-06-03

    您可以通過答題星輕松地創建試卷

    全階人生考試2018-06-03

    各種考試題,題庫,初中,高中,大學四六

    運動步數有氧達人2018-06-03

    記錄運動步數,積累氧氣值。還可偷

    每日養生app2018-06-03

    每日養生,天天健康

    體育訓練成績評定2018-06-03

    通用課目體育訓練成績評定