Docker Network Management - Micro Services Architecture Foundation

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/weixin_39329758/article/details/90756664

A, Docker network management

1, Dcoker default network management

Docker automatically create three network installation. Clients can see through the network management command.

sudo docker network ls

Below an example to demonstrate the default birdge network management

(1) Create and launch container

sudo run -itd --name=networktest ubuntu 

(2) use the network to view instructions view network details

sudo docker network inspect bridge

1.2 Custom Network Introduction

(1).Bridge networks

 

(2).Overlay network in swarm mode

 

(3).Custome network plguins

 

1.3 Custom bridge network

(1) to create a custom network

sudo docker network create --driver bridge isolated_nw

(2) using a custom network starting container

sudo docker run --network=isolated_nw -itd --name=nwtest busybox

(3) Add the container network management

sudo docker network connect bridge nwtest

(4) Disconnect the vessel network connection

sudo docker network disconnect isolated_nw nwtest

(5) removing the custom network

sudo docker network rm isolated_nw 

The network name will return after executing the command

 

Network communication between container 1.4

(1) Create a container

[1] Create a container bridge with two default network

sudo docker run -itd --name=container1 busybox



sudo docker run -itd --name=container2 busybox

[2] create a custom network using isolated_nw container

sudo docker run --network=isloated_nw -itd --name=container4 busybox

[3] add an isolated-nw network connections for container2

sudo docker network connect isolated_nw container2

(2) container address View

First of all containers entering the container2

sudo docker attach container2 

Then use the ifconfig command to see

The remaining two vessels are viewing address

(3) communication test vessel

Into the container 1, ping container 4

Fail container can not communicate in different network environments

Then into the container 2, the container 1 container 4 is connected with a communication test vessel IP.

success.

 

Conclusion: The container must communicate in the same network environment. The default network management of container can be used ip communication, can not communicate with the vessel name, you can customize.

 

Two, Docker Swarm cluster

1.docker swarm Use

(1) environment to build

Prepare three Ubuntu, docker version 1.2 or more, ip address fixed, TCP port 2377,7946,4789 open.

 

ip address is as follows:

 

area1: 192.168.35.128

 

worker1:192.168.35.130

 

worker2:192.168.35.132

 

(2)创建docker swarm集群

【1】在manger1上创建docker swarm集群

sudo docker swarm init --advertise-addr 192.168.35.128

图中红框表示用来添加work节点命令

【2】在管理节点用docker node ls 查看

(3)向docker swarm 集群添加工作节点

【1】启动另外两台docker机器

执行2.1中红框命令

--token后的参数自己生成每个人不一样

【2】再次查看

(4)向docker swarm集群部署服务

sudo docker service create --replicas 1 --name helloworld alpine ping docer.com

(5)查看dockerswarm 集群的服务

【1】用sudo docker service ls查看

【2】查看具体详情

【3】查看运行和分配情况

6.更改docker swarm集群服务副本数量

sudo docekr scale helloworld=5

查看

7.删除服务

对于不需要的服务,使用 sudo docker service rm helloworld 进行删除,会返回服务名称

8.访问服务

【1】在管理节点上执行图中命令查看网络列表

【2】在管理节点上创建overlay的自定义网络。

sudo docker network create \

         --driver overlay \

         my-multi-host-network

【3】再次部署

sudo docker service create \

         --network my-multi-host-network \

         --name my-web \

         --publish 8080:80 \

         --replicas 2 \

         nginx

【4】使用图示命令查看服务副本运行情况

【5】外界访问服务

打开浏览器使用任意一台机器节点IP急+8080进行服务访问

三、Volumes数据卷管理

1.数据卷的使用

【1】创建数据卷

docker volume create my-vol

【2】查看数据卷

docker volume ls

【3】核查数据卷

docker volume inspect my-vol

【4】删除数据卷

docker volume rm my-vol

删除成功后返回数据卷名称

2.启动容器并加载数据卷

【1】查看本机容器和数据卷

【2】确认本机docker文件系统中的容器和数据卷

【3】启动容器并挂载数据卷

sudo docker run -d \

         -it \

         --name devtest \

         --mount source=myvol,target=/app \

         busybox:latest

【4】再次查看

【5】检查容器详情

使用docker inspect 查看容器详情

【6】再次确认本机文件系统中的容器和数据卷

可以看出,新建的容器数据卷已自动生成在本地文件目录中。

Guess you like

Origin blog.csdn.net/weixin_39329758/article/details/90756664