Docker Learning notes seven: Docker network

Source: Internet
Author: User
Tags reserved docker run
Network Configuration

Install Docker automatically create three networks by default:

$ docker Network LS

network ID          NAME                DRIVER
7fca4eb8c647 Bridge bridge
9f904ee27bf5        none                null
CF03EE007FB4        host                Host
1 2 3 4 5 6 1 2 3 4 5-6

The Docker container runs on the bridge network by default. The default bridge does not support automatic service discovery, so the container name or the expected/etc/hosts ping will fail, but the custom Bridge network supports automatic service discovery, which can be based on ping of the container name. If you want to interconnect the default bridge support name and IP, you can use the Docker run--link command. Custom Bridge Network

$ docker Network Create Simple-network 69568e6336d8c96bbf57869030919f7c69524f71183b44d80948bd3927c87f6a $ docker Network Inspect simple-network [{' Name ': ' simple-network ', ' Id ': ' 69568e6336d8c96bbf57869030919f7c69 524F71183B44D80948BD3927C87F6A "," Scope ":" Local "," Driver ":" Bridge "," IPAM ": {" Driv
                    ER ":" Default "," Config ": [{" Subnet ":" 172.22.0.0/16 ",
    "Gateway": "172.22.0.1/16"}]}, "containers": {}, Options: {} }] $ docker network LS network ID NAME DRIVER 9f904ee27bf5 none null C          F03EE007FB4 Host host 7fca4eb8c647 Bridge C5ee82f76de3 ISOLATED_NW Bridge
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18-------------19 20 21 22 23 24 25 26 27-28 29 30 31, 32 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31-32

Use the Docker run--network=<network> option in the Custom Network boot container:

$ docker Run--NETWORK=ISOLATED_NW-ITD--name=container3 busybox 8C1A0A5BE480921D669A073393ADE66A3FC49933F08BCC5515B37B8144F6D47C $ docker Network inspect ISOLATED_NW [{] Na Me: "ISOLATED_NW", "Id": "1196a4c5af43a21ae38ef34515b6af19236a3fc48122cf585e3f3054d509679b", "Scope": "Lo
                Cal "," Driver ":" Bridge "," IPAM ": {" Driver ":" Default "," Config ": [ {}]}, "containers": {"8c1a0a5be480921d669a073393ade66a3fc49933f08bcc5515b37b
                8144f6d47c ": {" EndpointId ":" 93b2db4a9b9a997beb912d28bcfc117f7b0eb924ff91d48cfa251d473e6a9b08 ", "MacAddress": "02:42:ac:15:00:02", "ipv4address": "172.21.0.2/16", "ipv6address": " '}}, ' Options ': {}}]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18-------------19 20 21 22 23 24 25 26 27-28 1 2 3, 4 20 21 22 23 24 25 26 27 28 Overlay network using Docker Engine swarm mode

The overlay network created in the management node of swarm mode is available only to nodes in the cluster that require service, and when creating a overlay network, the management node automatically extends the overlay network to the node that is running the service task.

Create a service that overwrites the network and applies it to the management nodes in swarm:

# Create an overlay network ' my-multi-host-network '.
$ docker Network create \
  --driver overlay \
  --subnet 10.0.9.0/24 \ my-multi-host-network

400g6bwzd68jizzdx5pgyoe95

# Create a nginx service and extend the my-multi-host-network to nodes where
# the Serv Ice ' s tasks run.
$ docker Service Create--replicas 2--network my-multi-host-network--name my-web nginx 716thylsndqma81j6kkkb5aus

1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 The 12 13

The overlay network for Swarm is not available for containers that are started with Docker run rather than as part of the cluster. Create a swarm cluster

1. Create a swarm master:

$ docker-machine Create \
 D-virtualbox \
 --swarm--swarm-master \
 --swarm-discovery= "consul://$ ( Docker-machine IP mh-keystore): 8500 "\
 --engine-opt=" cluster-store=consul://$ (docker-machine IP mh-keystore) : 8500 "\
 --engine-opt=" cluster-advertise=eth1:2376 "\
 mhs-demo0
1 2 3 4 5 6 7 1 2 3 4 5 6-7

2. Create another host and add it to the Swarm cluster:

$ docker-machine create-d virtualbox \
     --swarm \
     --swarm-discovery= "consul://$ (docker-machine IP mh-keystore) : 8500 "\
     --engine-opt=" cluster-store=consul://$ (docker-machine IP mh-keystore): 8500 "\
     --engine-opt=" cluster-advertise=eth1:2376 "\
   mhs-demo1
1 2 3 4 5 6 1 2 3 4 5-6

3. View the machine and make sure all the hosts are up and running:

$ docker-machine ls

 NAME         ACTIVE   DRIVER       State     URL                         SWARM
 default      -        VirtualBox   Running   tcp://192.168.99.100:2376
 mh-keystore  *        virtualbox   Running   tcp:// 192.168.99.103:2376
 mhs-demo0    -        virtualbox   Running   tcp://192.168.99.104:2376   Mhs-demo0 (Master)
 mhs-demo1    -        virtualbox   Running   tcp://192.168.99.105:2376   Mhs-demo0
1 2 3 4 5 6 7 1 2 3 4 5 6-7 Create an overlay network

1. Set the Docker environment to the swarm host:

$ eval $ (docker-machine env--swarm mhs-demo0)
1 1

Use the Docker-machine--swarm flag to restrict the Docker command to separate swarm information.

2. Use the Docker Info command to view this swarm:

 $ docker Info containers:3 images:2 role:primary strategy:spread, filters:affinity, health, port, Dependency Nodes:2 mhs-demo0:192.168.99.104:2376└containers:2└reserved cpus:0/1└reserved memory:0. 021 gib└labels:executiondriver=native-0.2, Kernelversion=4.1.10-boot2docker, Operatingsystem=boot2docker 1.9.0 (TCL 6.4); master:4187d2c-wed Oct 14:00:28 UTC 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.