docker swarm 网络设置


docker swarm 网络设置

 

 

**********************

docker network

 

命令格式:docker network command

Usage:	docker network COMMAND

Manage networks

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

Run 'docker network COMMAND --help' for more information on a command.

create:创建网络

connect:将容器连接到网络上

disconnect:将容器从网络上断开

inspect:查看网络详细信息

 

prune:删除未使用的网络

rm:删除指定网络

 

 

*******************

docker network create

 

命令格式:docker network create [options] network_name

sage:	docker network create [OPTIONS] NETWORK

Create a network

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 copying 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

-d:网络驱动,默认为bridge

--subnet strings:设置ip网段

 

 

**********************

示例

 

创建网络:docker network create -d overlay --subnet 10.10.0.0/24 my_network

[root@centos docker-swarm]# docker network create -d overlay --subnet 10.10.0.0/24 my_network
3wtwakxnbnly2orj4otigbkxy

 

 

创建服务:docker service create  --network my_network --replicas 3 --name redis redis

[root@centos docker-swarm]# docker service create --network my_network --replicas 3 --name redis redis
py8515pesfqil4nrmgtxka1ab
overall progress: 3 out of 3 tasks 
1/3: running   [==================================================>] 
2/3: running   [==================================================>] 
3/3: running   [==================================================>] 
verify: Service converged 

 

查看服务:docker servce ps redis

[root@centos docker-swarm]# docker service ps redis
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE           ERROR               PORTS
1ii7nnbuhbef        redis.1             redis:latest        centos              Running             Running 6 minutes ago                       
2ia66det09qt        redis.2             redis:latest        centos              Running             Running 6 minutes ago                       
hspg5zdaoqk5        redis.3             redis:latest        centos              Running             Running 6 minutes ago                       

 

查看 ip地址

[root@centos docker-swarm]# docker inspect 76 |grep "IP"
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
                    "IPAMConfig": {
                        "IPv4Address": "10.10.0.4"
                    "IPAddress": "10.10.0.4",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,

 

[root@centos ~]# docker inspect d6 |grep "IP"
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
                    "IPAMConfig": {
                        "IPv4Address": "10.10.0.3"
                    "IPAddress": "10.10.0.3",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,


 

[root@centos ~]# docker inspect 6b |grep "IP"
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
                    "IPAMConfig": {
                        "IPv4Address": "10.10.0.5"
                    "IPAddress": "10.10.0.5",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,

ip 地址设置为指定网段范围地址

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值