docker三剑客(2) docker-machine安装&管理swarm

ubuntu     系统类型

test                       docker管理操作用户

192.168.1.73   swarm-node

192.168.1.80   swarm-master

1、swarm-master 创建集群

1.1 切换切换活跃主机

[email protected]:~$ docker-machine ls
NAME   ACTIVE   DRIVER    STATE     URL                       SWARM   DOCKER        ERRORS
73     *        generic   Running   tcp://192.168.1.73:2376           v17.06.0-ce
80     -        generic   Running   tcp://192.168.1.80:2376           v17.06.0-ce
[email protected]:~$ docker-machine active 80
Error: Too many arguments given
[email protected]:~$ docker-machine active
73
[email protected]:~$ eval $(docker-machine env 80)
[email protected]:~$ docker-machine active
80

1.2创建swarn镜像

[email protected]:~$ docker run swarm create
Unable to find image ‘swarm:latest‘ locally
latest: Pulling from library/swarm
248cc99c8148: Pull complete
0aeceddbda61: Pull complete
c90a34ed5817: Pull complete
Digest: sha256:02040b8e8292aacb6e30be8babd613f1c253a3ec665d2fbc178d1745810fdd29
Status: Downloaded newer image for swarm:latest
Token based discovery is now deprecated and might be removed in the future.
It will be replaced by a default discovery backed by Docker Swarm Mode.
Other mechanisms such as consul and etcd will continue to work as expected.
3e2a3fa482c1994ad5ee684f120e27c4

#最后一行为CLUSTER_ID一定保留下好,下面增加节点都会用到

1.3增加主控节点swarm-master

[email protected]:~$ docker-machine create --driver generic --swarm --swarm-master --swarm-discovery token://3e2a3fa482c1994ad5ee684f120e27c4 swarm-master
Error setting machine configuration from flags provided: generic driver requires the --generic-ip-address option
[email protected]:~$ docker-machine create --driver generic  --generic-ip-address=192.168.1.80   --generic-ssh-key ~/.ssh/id_rsa  --generic-ssh-user=test --swarm --swarm-master --swarm-discovery token://3e2a3fa482c1994ad5ee684f120e27c4 swarm-master
Running pre-create checks...
Creating machine...
(swarm-master) Importing SSH key...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Configuring swarm...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env swarm-master
[email protected]:~$ docker-machine ls
NAME           ACTIVE   DRIVER    STATE     URL                       SWARM                   DOCKER        ERRORS
73             -        generic   Running   tcp://192.168.1.73:2376                           v17.06.0-ce
80             *        generic   Running   tcp://192.168.1.80:2376                           v17.06.0-ce
swarm-master   *        generic   Running   tcp://192.168.1.80:2376   swarm-master (master)   v17.06.0-ce 

1.4 增加swarm节点

#普通节点没有--swarm-master选项

[email protected]:~$ docker-machine create --driver generic  --generic-ip-address=192.168.1.73   --generic-ssh-key ~/.ssh/id_rsa  --generic-ssh-user=test --swarm --swarm-discovery token://3e2a3fa482c1994ad5ee684f120e27c4 swarm-node1
Running pre-create checks...
Creating machine...
(swarm-node1) Importing SSH key...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with ubuntu(systemd)...
Installing Docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Configuring swarm...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env swarm-node1
[email protected]:~$ docker-machine ls
NAME           ACTIVE   DRIVER    STATE     URL                       SWARM                   DOCKER        ERRORS
swarm-master   *        generic   Running   tcp://192.168.1.80:2376   swarm-master (master)   v17.06.0-ce
swarm-node1    -        generic   Running   tcp://192.168.1.73:2376   swarm-master            v17.06.0-ce   

1.5 查看swarm状态

[email protected]:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
0jmswkqce9cqjvri9awdm37ty     swarm-node1         Ready               Active
69nkaqu3ivfmty5isz0ug0oiw *   swarm-master        Ready               Active              Leader

2管理swarm

2.1退出集群

[email protected]:~$ docker swarm  leave --force
Node left the swarm.

#使用docker-machine切换环境分别在swarm-node1,swarn-master退出集群,以下仅涉及到切换环境不提供代码参见1.1

2.2 swarm-master建立集群

[email protected]:~$ docker swarm  init
Swarm initialized: current node (69nkaqu3ivfmty5isz0ug0oiw) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-1qj2mfe14jw2tzhg1fxpqiyhxpnm4bqhrhae0dtpp6ip9og4s3-btyj7t5304eyeuhrl4dw1vx1l 192.168.1.80:2377

To add a manager to this swarm, run ‘docker swarm join-token manager‘ and follow the instructions.

#同样token很重要,不要丢失,docker代码提示很明白,加入集群命令摆在那里

2.3 swarm-node1 加入集群

[email protected]:~$ docker swarm join --token SWMTKN-1-1qj2mfe14jw2tzhg1fxpqiyhxpnm4bqhrhae0dtpp6ip9og4s3-btyj7t5304eyeuhrl4dw1vx1l 192.168.1.80:2377
This node joined a swarm as a worker.
[email protected]:~$ eval $(docker-machine env swarm-master)
[email protected]:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
0jmswkqce9cqjvri9awdm37ty     swarm-node1         Ready               Active
69nkaqu3ivfmty5isz0ug0oiw *   swarm-master        Ready               Active              Leader
时间: 2024-08-08 08:52:06

docker三剑客(2) docker-machine安装&管理swarm的相关文章

docker三剑客之应用machine,compose,swarm

利用Docker-Machine创建虚拟Docker主机 ## 下载docker-machine https://github.com/docker/machine/releases [email protected]:~$ curl -L https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && ch

docker——三剑客之Docker swarm

Docker Swarm是Docker官方的三剑客项目之一,提供Docker容器集群服务,是Docker官方对容器云生态进行支持的核心方案.使用它,用户可以将多个Docker主机封装为单个大型的虚拟Docker主机,快速打造一套容器云平台. Docker Swarm是Docker公司推出的官方容器集群平台,基于Go语言实现.目前,包括Rackspace在内的许多平台都采用了Swarm,用户很容易在AWS等公有云平台使用Swarm. Swarm的前身是Beam项目和libswarm项目,首个正式版

docker——三剑客之Docker Machine

Docker Machine是Docker官方三剑客项目之一,负责使用Docker的第一步,在多种平台上快速安装Docker环境.它支持多种平台,让用户在很短时间内搭建一套Docker主机集群. Machine项目是Docker官方的开源项目,负责实现对Docker主机本身进行管理.Machine项目主要由GO编写,用户可以在本地任意指定被Machine管理的Docker主机,并对其进行操作.Machine定位是"在本地或者云环境中创建Docker主机" Docker Machine是

docker三剑客之docker swarm

Swarm是什么 Swarm这个项目名称特别贴切.在Wiki的解释中,Swarm behavior是指动物的群集行为.比如我们常见的蜂群,鱼群,秋天往南飞的雁群都可以称作Swarm behavior. 安装 1.下载镜像 docker pull swarm docker run --rm swarm -v 2.配置节点 docker主机在加入swarm集群前,要进行配置,添加docker daemon的网络监听,例如,在启动docker daemon的时候通过-H参数: sudo docker

Docker 三剑客之Docker Swarm

Docker Swarm 介绍 创建Docker Swarm集群 1.使用docker machine ssh连接到想要成为manager node的那台docker宿主机上. $ docker-machine ssh manager1 2.执行下面的命令,创建一个swarm集群. docker swarm init --advertise-addr <MANAGER-IP> 例如: # docker swarm init --advertise-addr 43.241.208.252 Swa

docker三剑客之一docker compose

compose有两个重要的概念: 服务(service):一个应用的容器,实际上可以包括若干运行相同镜像的容器实例 项目(project):由一组关联的应用容器组成的一个完整业务单元,在docker-compose.yml文件中定义 compose默认管理对象是项目,通过子命令对项目中的一组容器进行便捷地生命周期管理 安装 pip安装,下载编译好的二进制文件,直接运行在docker容器中三种方案: pip安装: apt-get install python-pip -y pip install

docker——三剑客之Docker Compose

编排(Orchestration)功能是复杂系统实现灵活可操作性的关键.特别是在Docker应用场景中,编排意味着用户可以灵活的对各种容器资源实现定义和管理. 作为Docker官方编排工具,Compose的重要性不言而喻,它可以让用户通过编写一个简单模板文件,快速地创建和管理基于Docker容器地应用集群. Compose项目是Docker官方的开源项目,负责实现对Docker容器的快速编排.从功能上看,跟OpenStack中的Heat十分相似.Compose定位是"定义和运行多个Docker容

docker三剑客之docker compose

compose环境变量 以DOCKER_开头的变量和用来配置Docker命令行客户端的使用一样,如果使用boot2docker,${boot2dockershellinit}将会设置他们为正确的值 compose环境变量: COMPOSE_PROJECT_NAME: 设置compose的项目名称,默认是当前工作目录(docker-compose.yml文件所在目录)的名字 compose会为每一个启动的容器前添加项目名称.例如一个名称为proj的项目,其中的一个web容器,名称可能为proj_w

Docker三剑客之Swarm介绍

DockOne技术分享(二十): 我用swarm在多台物理机调度管理容器,用ovs实现跨主机的容器互联问题 [编者的话]Swarm项目是Docker公司发布三剑客中的一员,用来提供容器集群服务,目的是更好的帮助用户管理多个Docker Engine,方便用户使用,像使用Docker Engine一样使用容器集群服务.这次分享内容从Swarm项目现状.Swarm社区现状和Swarm未来的一些规划三方面介绍Swarm,目的是能让大家对Swarm有个完整的认识,并且希望更多的人采用到Swarm项目中来