我们生产环节中一定是 多host出现的,所以我用到docker-machine 管理工具,实现对多个host上面的docker的管理。

1、安装docker-machine
设置环境变量;
base=https://github.com/docker/machine/releases/download/v0.14.0
下载
curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine
设置环境变量
sudo install /tmp/docker-machine /usr/local/bin/docker-machine
此时可以执行docer-machine 相关指令,验证是否成功
[root@docker ~]# docker-machine --version
docker-machine version 0.14.0, build 89b8332

2、添加主机
1、设置无密码登陆
2、添加主机
[root@docker ~]# docker-machine create --driver generic --generic-ip-address=192.168.1.39 docker
Creating CA: /root/.docker/machine/certs/ca.pem
Creating client certificate: /root/.docker/machine/certs/cert.pem
Running pre-create checks...
Creating machine...
(docker) No SSH key specified. Assuming an existing key at the default location.
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 centos...

Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
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 docker
我们先把自己添加进来
此时查看执行这个命令的动作
[root@docker ~]# ps -ef|grep yum
root 13455 13333 0 20:41 pts/2 00:00:00 /usr/bin/ssh -F /dev/null -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none [email protected] -p 22 -tt sudo -E yum -y update -x docker-
root 13459 13456 0 20:41 pts/3 00:00:00 sudo -E yum -y update -x docker-

root 13472 13459 5 20:41 pts/3 00:00:13 /usr/bin/python /bin/yum -y update -x docker-*
root 13572 13502 0 20:45 pts/5 00:00:00 grep --color=auto yum
执行这个命令后,在升级安装 dicker 等插件

验证是否添加完成
[root@docker ~]# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
docker - generic Running tcp://192.168.1.39:2376 v1.13.1
[root@docker ~]#

2、添加第二台 host主机 (第二台host 配置和yum源和ssh无密码登陆,什么也不用做)
[root@docker ~]# docker-machine create --driver generic --generic-ip-address=192.168.1.40 docker-1
Running pre-create checks...
Creating machine...
(docker-1) No SSH key specified. Assuming an existing key at the default location.
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 centos...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
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 docker-1
[root@docker ~]# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
docker - generic Running tcp://192.168.1.39:2376 v1.13.1
docker-1 - generic Running tcp://192.168.1.40:2376 v18.05.0-ce
[root@docker ~]#